Data Structures & AlgorithmsVery hardCodeforces Div2 C · ICPC regional
What is the length of the longest substring of "aabbcabccbba" in which every letter occurs an EVEN number of times (0 counts as even)?
- A. 4
- B. 6
- C. 2
- D. 3
Correct answer: A. 4
Track the parity mask of letter counts over the prefix; a substring has all-even counts when two prefixes share the same mask, so the longest gap between equal masks is the answer. Checking only each letter's count parity along a window is slower and easy to get wrong.
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 unordered pairs of positions in [2, 8, 9, 18, 4, 6, 12] have a product that is a perfect square?
- For each window of 3 consecutive elements of [1, 2, 1, 3, 2, 1, 4], count the number of DISTINCT values in it. What is the sum of these…
- Repeatedly delete any adjacent pair of letters that are 'a' and 'b' (in either order) from "abbaabbbaab" until none remains. What is the…
- Cards with values [4, 1, 7, 3, 9, 2, 5] lie in a row. In each of 3 moves you take the card at the LEFT end or the RIGHT end. What is the…
- How many ordered sequences of positive integers, each at most 3 and with at least two terms, sum to 6?
- For the array [3, 5, 6, 1], compute the XOR of every non-empty contiguous subarray and add all these XOR values together. What is the total?