Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Starting at (0,0), a robot moves on an infinite grid using the string "UURDDLLUR" (U = up, D = down, L = left, R = right). The robot visits cells; how many distinct cells does it visit including the start?
- A. 10
- B. 8
- C. 7
- D. 1
Correct answer: B. 8
The path is (0,0), (0,1), (0,2), (1,2), (1,1), (1,0), (0,0), (−1,0), (−1,1), (0,1), with 8 distinct cells. Counting every position gives 10, dropping the start gives 7, and 1 is the final distance from the start.
More Coding Interview Problems questions
- Problem: The set S = {1, 2, 3, …, 30} is considered. How many integers in S are NOT divisible by 2, 3 or 5?
- Problem: A binary search over the sorted array [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] looks for the value 12 which is absent. Using the…
- Problem: The 10 numbers 1 to 10 are split into two groups of five. The sum of the group containing 10 is S. How many different values of S…
- Problem: In a directed acyclic graph with arcs 0→1, 0→2, 1→3, 2→3, 3→4, 2→4, how many distinct topological orders exist?
- Problem: Compute the number of trailing zeros of 25! in base 5 (that is, how many times 5 divides 25!).
- Problem: A stack starts with the characters pushed in the order a, b, c, d. The following pops occur: pop, pop, then push e, pop. Which…