Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ABHIINAV12/3d802f400b3799753f0b787d7961152a to your computer and use it in GitHub Desktop.
Save ABHIINAV12/3d802f400b3799753f0b787d7961152a to your computer and use it in GitHub Desktop.
class Solution {
public:
int findMinFibonacciNumbers(int k) {
long long int arr[50];
arr[1]=1; arr[2]=1;
for(int i=3;i<50;++i)
arr[i]=arr[i-1]+arr[i-2];
int ret=0;
while(k!=0){
ret++;
int l=1,h=49;
int poss=-1;
while(l<=h){
int mid=l+(h-l)/2;
if(arr[mid]<=k){
poss=mid;
l=mid+1;
}else{
h=mid-1;
}
}
k-=arr[poss];
}
return ret;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment