Data Structures & AlgorithmsModerateICPC regional · GATE CS
Problem: How many distinct values does the expression (a² + b²) mod 5 take as a and b range over 0 ≤ a, b ≤ 4?
- A. 5
- B. 6
- C. 4
- D. 7
Correct answer: A. 5
Squares mod 5 are 0, 1 and 4, and sums of two of these cover every residue class mod 5. Counting only the squares of single values gives 3.
More Coding Interview Problems questions
- 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…
- Problem: The string "abacaba" is processed: each character is replaced by the number of times it has appeared so far (including this…
- Problem: Two heaps are used to track the minimum and maximum of a sliding window of size 3 over [4, 8, 1, 9, 3, 7]. How many windows have…
- Problem: The product of the digits of 2^10 · 3^4 is computed (in decimal). What is that product?
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is reduced by repeatedly removing the first two elements and appending their sum to the…
- Problem: For the sequence 2, 3, 5, 7, 11, …, the first 10 prime numbers are listed. What is the sum of the 10th and 7th primes in the list?