Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional
What is the maximum value of x XOR y over all pairs of DIFFERENT positions of the list [7, 12, 5, 9, 14, 3]?
- A. 15
- B. 2
- C. 13
- D. 14
Correct answer: A. 15
Build a binary trie of the values from the most significant bit and greedily choose the opposite bit at each level, which finds the best partner in O(n · bits). Brute force over pairs gives the same answer for small inputs.
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
- Consider all non-empty contiguous subarrays of [2, 7, 3, 8, 6]. For each, take its sum modulo 10. What is the largest of these residues?
- A robot walks from the top-left corner of a 3 × 4 grid of cells to the bottom-right corner, moving only right or down. How many such paths…
- Two lists a = [4, 9, 1, 7] and b = [3, 8, 2, 10] are paired one-to-one (any bijection). What is the minimum possible value of the sum of…
- In the sequence [1, 3, 5, 2, 4, 6], how many strictly increasing subsequences have the maximum possible length (count by index positions)?
- Consider the routine that computes the length of the longest STRICTLY increasing subsequence of [2, 2, 3, 3, 4, 4, 5] using the tails…
- How many unordered pairs of positions of the same letter are there in "abracadabra" (i < j with s[i] = s[j])?