Data Structures & AlgorithmsModerate
From the array 1 5 3 3 3 7 2 4 6, choose the largest number of PAIRS of positions so that every position is used in at most one pair and each pair sums to 6. What is that maximum number of pairs?
- A. 5
- B. 3
- C. 4
- D. 2
Correct answer: B. 3
Pairs must be disjoint, so the problem is maximum matching in a graph where equal-complement values connect. Counting all qualifying index pairs over-counts overlapping ones, and the half-length bound ignores which values actually match.
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 3 2 2 4 4 4 4 1 in which EVERY distinct value appears an even number of…
- Using only swaps of ADJACENT characters, what is the minimum number of swaps needed to turn the string "abcab" into a palindrome?
- From the string "aabbaabba" you may repeatedly delete any two ADJACENT characters that are different (one 'a' and one 'b'). What is the…
- For 5 2 7 1 4 6 3, how many split points i (0 ≤ i ≤ n−2) have XOR(A[0..i]) equal to XOR(A[i+1..n−1])?
- What is the length of the shortest contiguous block of 1 3 9 4 6 5 7 8 that, if sorted in place by itself, makes the WHOLE array sorted in…
- How many positions i in 0 1 2 2 3 1 4 satisfy: the value A[i] equals the number of elements BEFORE position i that are strictly smaller…