Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A grid of 2 rows and 5 columns is numbered row by row from 1. Each cell (r, c) holds (r·5 + c + 1). What is the value of the cell in row 1, column 3 (both 0-indexed)?

  1. A. 9
  2. B. 3
  3. C. 8
  4. D. 17

Correct answer: A. 9

Row-major with 0-indexing: 1 · 5 + 3 + 1 = 9. Reading (1, 3) as 1-indexed gives 3, dropping the + 1 gives 8, and swapping the row and column roles gives 3 · 5 + 1 + 1 = 17.

More Coding Interview Problems questions

Exams that ask this topic