Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Starting at 0 on a line, a walker takes steps +3, −2, +3, −2, … alternating, with 12 steps in total. How many distinct integer positions does the walker visit (including the start 0)?
- A. 13
- B. 9
- C. 8
- D. 6
Correct answer: B. 9
Positions are 0, 3, 1, 4, 2, 5, 3, 6, 4, 7, 5, 8, 6, so the distinct ones are 0..8: 9. Counting visits without de-duplicating gives 13, leaving out the start 0 gives 8, and 6 is just the final position.
More Coding Interview Problems questions
- Problem: Count the sequences of length 5 over {0, 1, 2} with no two adjacent equal digits and whose first digit is 0.
- Problem: The sorted array [1, 4, 4, 9, 12, 12, 15, 20] (0-indexed) may contain repeated values. Using a lower-bound search, which returns…
- Problem: How many subarrays of [1, 2, 2, 3] have max minus min at most 1? Run the code. python a = [1, 2, 2, 3] print(sum(1 for i in…
- Problem: How many peaks (elements strictly greater than both neighbours, excluding the two ends) does [1, 3, 2, 4, 1, 5] have? Run the…
- Problem: What does this run-length encoder print for 'aaabccdd'? python s = 'aaabccdd' out = [] i = 0 while i < len(s): j = i while j <…
- Problem: Check bracket balance for '([]{})' and '([)]' with a stack. What is printed? python def ok(s): pairs = {')': '(', ']': '[', '}'…