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 = 1F2 = 1Fn = Fn-1 + Fn-2forn > 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
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code