Data Structures & AlgorithmsHard
How many index pairs i < j in 1 2 3 4 6 8 satisfy A[i]·A[j] ≥ 2·(A[i] + A[j])?
- A. 4
- B. 5
- C. 10
- D. 1
Correct answer: B. 5
Rewrite as (x−2)(y−2) ≥ 4, which shows that pairs with a small value (1 or 2) never qualify. Strict inequality, a weaker bound, or the exact equality each change the count.
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
- Why is a sum of XORs over subarrays NOT equal to the sum of the subarray sums?
- When counting subarrays with sum divisible by m, why does the prefix-remainder method count pairs of equal remainders?
- To count ordered pairs (i, j), i ≠ j, with A[i] + A[j] ≡ 0 (mod 5), which correction turns an unordered-pair count into the ordered one?
- When counting subarrays, why do two blocks with identical values but different positions count as two different subarrays?
- In the 'shortest window with a then b in order' problem, why does taking the nearest later 'b' for each 'a' suffice?
- Why is the maximum product of three values sometimes achieved by two large negatives and one large positive?