Skip to main content

Practice · 2 of 3

Count the Complement

CHALLENGE
Difficulty: advanced+25 XP

**Scenario.** n ≤ 10^6 numbers. Count pairs (i, j), i < j, whose sum is NOT divisible by 7. Direct checking is O(n²) — dead. What is the restructure? **Which approach is the best fit? The program only needs to print the letter.** **A)** Loop pairs but break early when the sum is divisible **B)** Count pairs whose sum IS divisible (easy from residues mod 7), then subtract from n(n−1)/2 **C)** Sort and use two pointers on the sum **D)** Hash every pair sum into a set

Back to lesson: Practice: Decomposition Drills