Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: How many integers n with 1 ≤ n ≤ 500 satisfy n mod 3 = n mod 5 ?
- A. 68
- B. 100
- C. 102
- D. 101
Correct answer: D. 101
n mod 3 = n mod 5 exactly when n mod 15 ∈ {0, 1, 2}; there are 33 full blocks of 15 (99 values) plus 496 and 497, so 101. Forgetting residue 0 gives 68, the estimate 500 × 3 / 15 gives 100, and starting the count at n = 0 gives 102.
More Coding Interview Problems questions
- Problem: A matrix of size 4×4 is filled row-wise with 1 to 16 (row 0 holds 1–4, row 1 holds 5–8, and so on). It is rotated 90 degrees…
- Problem: In the string "racecarbanana", find the number of distinct palindromic substrings of length at least 3.
- Problem: On a line of 12 cells (1–12), a robot starts at cell 1. Each second it moves to the cell i+3 if that cell is still ≤ 12 and not…
- Problem: A string is built by writing the first 15 positive integers in binary, concatenated in order (1, 10, 11, 100, ..., 1111). How…
- Problem: A sorted array [1, 3, 3, 5, 8, 8, 8, 13, 21] is searched for the value 8 using the standard lower-bound binary search (find the…
- Problem: A tree has 7 nodes 1–7 with edges 1-2, 1-3, 2-4, 2-5, 3-6, 6-7. Each node is coloured red if its depth from node 1 is even and…