Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: How many integers in [1, 200] are divisible by exactly one of 6 and 8?
- A. 42
- B. 50
- C. 58
- D. 54
Correct answer: A. 42
Multiples of 6: 33, of 8: 25, of both (lcm 24): 8, so exactly one is 33 + 25 − 2·8 = 42. Subtracting the overlap only once gives the union 50, not subtracting it gives 58, and using 48 instead of the lcm 24 gives 33 + 25 − 4 = 54.
More Coding Interview Problems questions
- Problem: The Euler's criterion test: count the quadratic residues modulo 13 among 1 through 12 (a residue r satisfies x² ≡ r for some…
- Problem: How many 4-digit numbers (1000 to 9999) have all four digits distinct and in strictly decreasing order from left to right?
- Problem: Compute the sum of the digits of the number 2^20 × 5^18 written in decimal.
- Problem: Let f(n) = number of 1-bits in n. Compute Σ f(n) for n from 0 to 63 inclusive.
- Problem: Starting at (0,0), the robot moves in the string "NNEESSWWNE" with N = up, E = right, S = down, W = left. Count the number of…
- Problem: The sequence a1 = 2, and each next term is a(n+1) = (a(n) × 3 + 1) mod 11. What is a(20)?