Tap here to switch tabs
Problem
Submissions

Problem: Minimum Jumps to Reach Home

Try to solve the Minimum Jumps to Reach Home problem.

Statement

A bug starts at position 00 on the number line and wants to reach its home located at position x.

The bug can move according to the following rules:

  • It can jump forward by a positions (moving to position curr + a).

  • It can jump backward by b positions (moving to position curr - b).

  • It cannot jump backward twice consecutively.

  • It cannot land on any position present in the array forbidden.

  • It cannot jump to any negative positions.

Return the minimum number of jumps required for the bug to reach position x. If it is impossible to reach position x, return −1-1.

Constraints:

  • 1≤1 \leq forbidden.length ≤1000\leq 1000

  • 1≤1 \leq a, b, forbidden[i] ≤2000\leq 2000

  • 0≤0 \leq x ≤2000\leq 2000

  • All elements in forbidden are distinct.

  • Position x is not forbidden.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Jumps to Reach Home

Try to solve the Minimum Jumps to Reach Home problem.

Statement

A bug starts at position 00 on the number line and wants to reach its home located at position x.

The bug can move according to the following rules:

  • It can jump forward by a positions (moving to position curr + a).

  • It can jump backward by b positions (moving to position curr - b).

  • It cannot jump backward twice consecutively.

  • It cannot land on any position present in the array forbidden.

  • It cannot jump to any negative positions.

Return the minimum number of jumps required for the bug to reach position x. If it is impossible to reach position x, return −1-1.

Constraints:

  • 1≤1 \leq forbidden.length ≤1000\leq 1000

  • 1≤1 \leq a, b, forbidden[i] ≤2000\leq 2000

  • 0≤0 \leq x ≤2000\leq 2000

  • All elements in forbidden are distinct.

  • Position x is not forbidden.