Data Structures & AlgorithmsModerateTCS NQT · CAT
Problem: Find the number of integer pairs (a, b) with 1 ≤ a ≤ b ≤ 12 such that a and b have the same remainder when divided by 4.
- A. 12
- B. 36
- C. 78
- D. 24
Correct answer: D. 24
Each residue class mod 4 has 3 numbers, giving C(3,2) + 3 = 6 pairs with a ≤ b, so 4 · 6 = 24. Excluding a = b gives 12, ordered pairs give 36, and 78 counts all pairs a ≤ b.
More Coding Interview Problems questions
- Problem: Consider the directed graph with arcs 1→2, 2→3, 3→1, 3→4, 4→2, 4→5. How many vertices can reach vertex 5?
- Problem: A string of length 6 is formed using letters only from {a, b}, containing no substring "aa" or "bb". How many such strings are…
- Problem: Compute the number of paths of length exactly 3 from vertex 0 to vertex 2 in the undirected graph with edges 0-1, 1-2, 0-2, 2-3…
- Problem: The sum of all positive integers up to 500 that are divisible by 3 but not by 5 is what value?
- Problem: How many distinct values does the expression (a² + b²) mod 5 take as a and b range over 0 ≤ a, b ≤ 4?
- Problem: In the array [9, 4, 7, 1, 8, 2], the element 7 is at index 2. Find the number of elements to the right of index 2 that are…