Data Structures & AlgorithmsHardCodeforces Div2 C · LeetCode-style

Positions 0 to 9 form a line. Cells marked 1 are blocked, the rest are free. From a cell you may jump forward by at most 3 positions (to any free cell in that range). Starting at 0, what is the minimum number of jumps to reach the last cell, or −1 if impossible?

  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 6

Correct answer: C. 4

BFS or a DP over cells: dist[i] = 1 + min dist[j] over free j within k steps behind i, with blocked cells unreachable. Jumping greedily to the farthest free cell can be impossible because of blocks.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic