Data Structures & AlgorithmsModerateTCS NQT · Infosys
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 distinct cells it visits (the start included, revisits counted once).
- A. 11
- B. 9
- C. 10
- D. 8
Correct answer: B. 9
The path revisits (0,0) and (0,1), so the distinct cells are 11 positions − 2 repeats = 9. Counting every position gives 11, counting moves gives 10, and leaving out the start cell gives 8.
More Coding Interview Problems questions
- Problem: The sequence a1 = 2, and each next term is a(n+1) = (a(n) × 3 + 1) mod 11. What is a(20)?
- Problem: A bag holds coins of values 1, 4 and 9. You must pay exactly 30 using as few coins as possible. What is the minimum number of…
- Problem: The 0/1 matrix [[1,0,1],[1,1,0],[0,1,1]] is considered. A 'plus' is a centre cell with value 1 whose four neighbours (up, down…
- Problem: Two heaps are maintained over the stream 5, 15, 1, 3, 8, 7, 9, 10, 6, 11 to report the median after each element (lower median…
- Problem: The string "abcabcbb" is scanned and for each position the length of the longest run of distinct characters starting at that…
- Problem: Dijkstra's algorithm in an undirected graph with edges 0-1 (2), 1-2 (2), 0-2 (5), 2-3 (1), 1-3 (6). How many vertices have a…