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)?
- A. 9
- B. 3
- C. 8
- 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
- Problem: Vertices 0–5 are connected by weighted undirected edges: 0-1 (2), 0-2 (4), 1-2 (1), 1-3 (7), 2-4 (3), 3-4 (2), 3-5 (1), 4-5 (5)…
- Problem: Consider the undirected graph with edges 0-1, 1-2, 2-0, 2-3, 3-4 and 4-5, 5-3. A DFS from vertex 0 (visiting neighbours in…
- Problem: Counting sort is applied to [3, 1, 2, 3, 0, 1] with keys in the range 0 to 3. After counting occurrences and computing prefix…
- Problem: The string "aaabbcccc" has its runs counted. What is the length of the longest run of identical characters?
- Problem: How many integers from 1 to 300 are divisible by 4 or 6 but not by 12?
- Problem: A list of numbers is [10, 4, 9, 7, 5, 12]. A "peak" is an element strictly greater than both of its neighbours (end elements have…