Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
In the string "bbaacbbaaac", what is the length of the shortest contiguous substring that contains at least three letters 'a'?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Sliding window over positions of 'a': the minimum is the span of any three consecutive 'a' positions. Taking the first valid window rather than the shortest is the usual error.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Piles of bananas are [3, 6, 7, 11] and you must finish all piles within 8 hours, eating at speed k bananas per hour (taking ceil(pile / k)…
- The array [7, 2, 5, 10, 8] is split into exactly 2 non-empty contiguous parts so that the largest part sum is as small as possible. What…
- How many non-empty contiguous subarrays of [4, 5, 0, -2, -3, 1] have a sum divisible by 5 (including negative sums, which are divisible…
- An array of 6 zeros (indices 0 to 5) receives three range-add operations, each adding v to every index from l to r inclusive: (1,3,+2)…
- The stock span of day i is the number of consecutive days up to and including i with price at most price[i]. What is the sum of the spans…
- For the circular array [1, 2, 1], the next greater element of each position searches forward and wraps around to the start, with -1 when…