VOOZH about

URL: https://www.geeksforgeeks.org/dsa/minimum-number-of-fibonacci-jumps-to-reach-end/

⇱ Minimum number of Fibonacci jumps to reach end - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Minimum number of Fibonacci jumps to reach end

Last Updated : 12 Jul, 2025

Given an array of 0s and 1s, If any particular index i has value 1 then it is a safe index and if the value is 0 then it is an unsafe index. A man is standing at index -1(source) can only land on a safe index and he has to reach the Nth index (last position). At each jump, the man can only travel a distance equal to any Fibonacci Number. You have to minimize the number of steps, provided man can jump only in forward direction.
Note: First few Fibonacci numbers are - 0, 1, 1, 2, 3, 5, 8, 13, 21....
Examples: 
 

Input: arr[]= {0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0} 
Output: 3
The person will jump from: 
1) index -1 to index 4 (a distance of jump = 5) 
2) index 4 to index 6 (a distance of jump = 2) 
3) index 6 to the destination (a distance of jump = 5)
Input: arr[]= {0, 0} 
Output: 1
The person will jump from: 
1) index -1 to destination (a distance of jump = 3) 
 


 


Approach: 
 

  • First, we will create an array fib[] for storing fibonacci numbers.
  • Then, we will create a DP array and initialize it with INT_MAX and the 0th index DP[0] = 0 and will move in the same way as Coin Change Problem with minimum number of coins.
  • The DP definition and recurrence is as followed:
     
     DP[i] = min( DP[i], 1 + DP[i-fib[j]] )
    
    where i is the current index and j denotes
    the jth fibonacci number of which the
    jump is possible
    • Here DP[i] denotes the minimum steps required to reach index i considering all Fibonacci numbers.


    Below is the implementation of the approach: 
     


    Output: 
    3

     

    Time Complexity: 
     

Comment