Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: What is the smallest positive integer n such that 1 + 2 + … + n is divisible by 10?
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: B. 4
The triangular number n(n+1)/2 must be a multiple of 10. Testing only n that are multiples of 10 misses the smallest one, which is found by direct search.
More Coding Interview Problems questions
- Problem: Compute 7^100 mod 13.
- Problem: Using US coin denominations 1, 5, 10, 25, what is the minimum number of coins needed to make 63 (greedy works for these…
- Problem: Count the walks of length 3 on the path graph P4 (vertices 1–4, edges 1-2, 2-3, 3-4) that start and end at the same vertex. Walks…
- Problem: The array [2, 7, 4, 1, 8, 1] is examined by a sweep: for each index i, the value a[i] is compared with the minimum of the…
- Problem: Starting with the stack [1] (top is the rightmost element), the operations are: push 2, push 3, pop, push 4, push 5, pop, pop…
- Problem: A bank processes queued withdrawals of 40, 25, 60, 15, 30 from a balance of 100. Each withdrawal is processed only if the current…