Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many ordered pairs (i, j) with i != j in [1, 3, 2, 6, 4] have a[i] AND a[j] = a[i], meaning the bits of a[i] are a subset of the bits of a[j]?
- A. 5
- B. 3
- C. 2
- D. 4
Correct answer: D. 4
The bitmask subset test is a AND b = a. Ordered pairs matter because subset-of is directional; the unordered variant (the last option) mis-counts.
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
- What is the length of the longest contiguous subarray of [1, 2, 1, 3, 4, 3, 5] in which at most one element is a repeat of an earlier…
- How many trailing zeros does 50! (50 factorial) have in decimal?
- How many palindromic substrings of length at least 3 does "racecarxyzzyx" contain (counted by position)?
- For each value n in [10, 27, 50], count the positive integers x with x^3 <= n, then add the three counts. What is the total?
- How many adjacent positions in [3, 9, 4, 7, 1] have a[i] > a[i+1]?
- What is the minimum number of characters that must be inserted at the front of "abcdc" to make it a palindrome?