Data Structures & AlgorithmsHardICPC regional · TCS NQT Digital
Problem: Count the sequences of steps from {1, 2, 5} that sum to exactly 10 (the order of steps matters).
- A. 10
- B. 128
- C. 75
- D. 89
Correct answer: B. 128
Ordered sequences satisfy f(n) = f(n − 1) + f(n − 2) + f(n − 5) with f(0) = 1, giving f(10) = 128. Treating the steps as an unordered multiset (coin-change loop order) gives 10, an off-by-one f(9) gives 75, and forgetting the 5-step leaves F(11) = 89.
More Coding Interview Problems questions
- Problem: A robot starts at (0, 0) facing north on an unbounded grid. Instructions: 'G' moves one step forward; 'L' turns 90° left; 'R'…
- Problem: Elevator starts at floor 0. Requests arrive in order for floors 3, 1, 4 (the elevator serves each request by going directly to…
- Problem: A traffic light cycles green for 30 s, then yellow for 5 s, then red for 25 s, starting at time 0 with green. How many whole…
- Problem: A water-jug problem: a 3-litre jug and a 5-litre jug, both empty, and unlimited water. Allowed actions: fill a jug fully, empty a…
- Problem: The string "PAYPALISHIRING" is written in a zigzag on 3 rows (letters go down the rows in a zigzag, then the rows are read left…
- Problem: How many ordered pairs (i, j) with 1 ≤ i < j ≤ 10 satisfy i XOR j = 3?