Mid/SeniorGreedyMath

Find the Minimum Number of Fibonacci Numbers Whose Sum Is K

Given an integer k, return the minimum number of Fibonacci numbers whose sum is equal to k. The same Fibonacci number can be used multiple times.

The Fibonacci numbers are defined as:

  • F1 = 1
  • F2 = 1
  • Fn = Fn-1 + Fn-2 for n > 2

It is guaranteed that for the given constraints we can always find such Fibonacci numbers that sum up to k.

Example 1
Inputk = 7
Output2
The Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, ...; for k = 7 we can use 2 + 5 = 7.
Example 2
Inputk = 10
Output2
For k = 10 we can use 2 + 8 = 10.

Constraints

  • 1 <= k <= 10^9

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate