Find the Minimum Number of Fibonacci Numbers Whose Sum Is K - Problem

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.

Input & Output

Example 1 — Basic Case
$ Input: k = 7
Output: 2
💡 Note: The Fibonacci numbers are 1, 1, 2, 3, 5, 8... We can represent 7 as 5 + 2, so we need minimum 2 Fibonacci numbers
Example 2 — Single Number
$ Input: k = 8
Output: 1
💡 Note: 8 is already a Fibonacci number, so we only need 1 Fibonacci number
Example 3 — Larger Number
$ Input: k = 15
Output: 3
💡 Note: 15 can be represented as 8 + 5 + 2, requiring 3 Fibonacci numbers

Constraints

  • 1 ≤ k ≤ 109

Visualization

Tap to expand
Find Minimum Fibonacci Numbers: k=15Input:15Fibonacci Sequence:11235813Greedy Selection:15 - 8 = 77 - 5 = 22 - 2 = 0852Answer: 3 numbers (8 + 5 + 2 = 15)Output:3
Understanding the Visualization
1
Input
Given k=15, find minimum Fibonacci numbers
2
Process
Use greedy: pick largest Fibonacci ≤ k
3
Output
Count of numbers needed: 3
Key Takeaway
🎯 Key Insight: Greedy works because of Zeckendorf's theorem - always pick the largest Fibonacci number that fits
Asked in
Google 15 Facebook 12
23.4K Views
Medium Frequency
~15 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen