Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many non-empty subarrays of [1, 2, 1, 2, 3, 3, 1] contain every value an even number of times?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
Track the parity mask of counts: a subarray is valid when its prefix parity mask at both ends is equal. Counting equal masks among prefixes gives the count in linear time.
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
- Flowers bloom on the days [1, 10, 3, 10, 2]. You need to make 2 bouquets, each from 2 adjacent bloomed flowers (flowers may only be used…
- In the binary array [1, 1, 0, 1, 1, 1, 0, 1, 1], you may flip exactly one 0 to 1 (or flip none). What is the length of the longest run of…
- How many index pairs i < j in [4, 9, 1, 7, 3, 8, 2] have a sum s with 6 <= s <= 10?
- How many contiguous subarrays of [10, 5, 2, 6] have a product strictly less than 100?
- Greedy removal: scanning "aabaacaab" left to right, you delete any 'a' that immediately follows another 'a' in the current output. How…
- Remove exactly 2 digits from "7419" (keeping order) to make the largest possible number. What is the result?