Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Liutauras Vilda
• Paul Clapham
• Bear Bibeault
• Jeanne Boyarsky
Sheriffs:
• Ron McLeod
• Tim Cooke
• Devaka Cooray
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Jj Roberts
• Stephan van Hulst
• Carey Brown
Bartenders:
• salvin francis
• Scott Selikoff
• fred rosenberger

Ranch Hand
Posts: 648
I have problem understanding this question and I can not understand how 4 is derived since 2 and 1 inside the span of 1 is 3.

So far I have tried out traverse the array backward but really my mind is blank from what to do next.  Please give me some tips.
I hope someone can give me an estimate time for a person without CS degree to practise good enough to go for coding interview.
Is 2 months too long or too short consider I need to fulfull a temp job duty?

Tks.

Bartender
Posts: 4103
156
hi Tangara,

two ways that come to my mind:

1) use indexOf and "lastIndexOf"

2) create a Map<Character, List<indices>>. The span of a character is then: last index - first index + 1

Marshal
Posts: 70625
288
Please stick to one question at a time.
Consider traversing the array from both ends towards its centre. If you find 99 on the left, search frorn the right until you find 99.

Marshal
Posts: 25946
69

The span between the first and last 1 is "1, 2, 1, 1". The word "inclusive" in the question means you should "include" the 1's which are the end points. You'll then observe that there are 4 numbers in that span.

 There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once. Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton