Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: What is the number of lattice points (x, y) with x, y ≥ 0 and x + y ≤ 5?

  1. A. 36
  2. B. 15
  3. C. 21
  4. 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

Exams that ask this topic