Data Structures & AlgorithmsHard
In the string "abciiidefoeuxyz", what is the largest number of vowels (a, e, i, o, u) that appear in any contiguous window of length 3?
- A. 4
- B. 3
- C. 2
- D. 8
Correct answer: B. 3
A fixed-length window's vowel count changes by at most one per slide, so update it in O(1) and track the maximum. Using a different window length, or counting vowels in the whole string, measures other things.
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 length of the longest contiguous substring of "aabbccabcdd" in which EVERY distinct letter appears at least twice?
- How many contiguous windows of length exactly 5 in 1 2 3 4 5 6 7 8 9 10 2 have a PRIME sum?
- How many contiguous subarrays of 2 4 6 4 2 8 have an AVERAGE exactly equal to the average of the whole array?
- For 3 9 1 7 2 8 4, split the array into a non-empty left part and a non-empty right part at some position p. What is the LARGEST possible…
- Using only swaps of ADJACENT characters, what is the minimum number of swaps needed to move ALL letters 'x' of "bxaxxbx" to the very front…
- From the digit string "53412", delete EXACTLY two characters (the remaining characters keep their order). What is the lexicographically…