Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA
In "xxyxxzxxx", what is the length of the longest substring that contains at most one character other than 'x'?
- A. 7
- B. 5
- C. 6
- D. 9
Correct answer: C. 6
Sliding window that tracks the count of non-'x' characters and allows at most one. The longest such window is "xxzxxx" around the z, of length 6.
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
- How many index pairs i < j of [1, 2, 3, 4, 5] have a sum equal to the array's maximum?
- Keeping only a palindrome (as a subsequence) of "abcba" needs no deletion at all, since the string is a palindrome already. What is the…
- What is the maximum number of pairwise disjoint contiguous subarrays of [2, 3, 1, 4, 2, 3, 5] that each have sum at least 5 (taken from…
- How many integers n with 1 <= n <= 200 have both n and n + 2 prime?
- How many windows of size 3 in [2, 9, 3, 4, 1, 1, 6] have a maximum strictly greater than the sum of the other two elements?
- From [7, 2, 9, 4, 6, 1], delete exactly one contiguous block of length 2. What is the smallest possible value of (max minus min) of the…