Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
What is the length of the longest contiguous substring of "bbacbbcab" containing at most one letter 'a'?
- A. 9
- B. 4
- C. 7
- D. 2
Correct answer: C. 7
Slide a window that holds at most one 'a': 'bbacbbc' (indices 0–6) has one a and length 7, and no window of 8 qualifies. 9 is the whole string with two a's, 4 allows no 'a' at all ('cbbc'), and 2 counts the a's.
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
- What is the sum of a XOR (a >> 1) over a = 5, 8 and 13 (where >> is a right shift by one bit)?
- How many index pairs i < j in [2, 5, 4, 10, 3, 15] have a product that is a multiple of 10?
- With weight limit 15, what is the maximum number of items from [5, 3, 8, 2, 7, 4] you can carry (choose any subset)?
- How many integers from 1 to 500 inclusive are divisible by 4 but not by 6?
- How many different output orders can a stack produce from the input 1, 2, 3, 4 pushed in order?
- In "abccbaxyz", take the longest palindromic substring (the first one if tied) and count its distinct characters.