Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
How many contiguous subarrays of [1, 2, 3, 4, 5] have a bitwise XOR less than 4?
- A. 12
- B. 8
- C. 10
- D. 14
Correct answer: C. 10
XOR is not monotone in the subarray length, so no sliding window works directly. Prefix XOR with a bit-trie or direct enumeration on this small array is the reliable route.
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 integers x with 1 <= x <= 200 satisfy gcd(x, 180) = 1?
- What is the smallest x such that lcm(1, 2, ..., x) exceeds 1,000,000?
- How many integers x with 1 <= x <= 100 satisfy x^2 mod 24 = 1?
- How many ordered pairs (i, j) with 1 <= i, j <= 18 have i j divisible by 18?
- How many contiguous subarrays of [2, 8, 3, 3, 2, 6] have a product that is a perfect square?
- How many contiguous subarrays of [1, 3, 2, 6, 4, 2] have a sum divisible by their length?