Data Structures & AlgorithmsModerateCAT · TCS NQT
Problem: What is the number of lattice points (x, y) with x, y ≥ 0 and x + y ≤ 5?
- A. 36
- B. 15
- C. 21
- D. 10
Correct answer: C. 21
For x = 0..5 there are 6 − x values of y: 6 + 5 + 4 + 3 + 2 + 1 = 21. The full 6 × 6 square gives 36, x + y < 5 gives 15, and requiring x, y ≥ 1 gives 10.
More Coding Interview Problems questions
- Problem: The array [5, 1, 4, 2, 3] is sorted by repeatedly swapping adjacent elements that are out of order (bubble sort). How many passes…
- Problem: The Hamming weight (number of 1-bits) of each integer from 0 to 15 is summed. What is the total?
- Problem: A set of letters {A, B, C, D, E} is arranged in a row. How many arrangements have A immediately to the left of B?
- Problem: The number of ways to split a line of 6 people into 2 groups of 3 (groups are distinguishable by their first member, so each…
- Problem: The string "racecar" is compared with its reverse position by position. How many positions have matching characters?
- Problem: Starting with the number 1, double it and add 1 repeatedly. What is the value after the 10th doubling step (starting value 1, 10…