File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ // https://www.interviewbit.com/problems/sum-of-fibonacci-numbers/
2
+
1
3
int Solution::fibsum (int n) {
2
4
vector <int > fib;
3
5
fib.push_back (1 );fib.push_back (1 ); // now u have 1 and 1 at v[0] and v[1]
@@ -17,3 +19,43 @@ int Solution::fibsum(int n) {
17
19
}
18
20
return ans;
19
21
}
22
+
23
+
24
+
25
+ // int Solution::fibsum(int A) {
26
+ // // Do not write main() function.
27
+ // // Do not read input, instead use the arguments to the function.
28
+ // // Do not print the output, instead return values as specified
29
+ // // Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
30
+
31
+ // vector<int> vec;
32
+
33
+ // vec.push_back(1);
34
+ // vec.push_back(1);
35
+
36
+ // int fib, i = 2;
37
+
38
+ // while(fib <= A){
39
+ // fib = vec[i-2] + vec[i-1];
40
+ // vec.push_back(fib);
41
+ // i++;
42
+ // }
43
+
44
+ // int j = vec.size()-1;
45
+ // int sol = 0;
46
+
47
+ // LOOP:while(A && j >= 0){
48
+ // if(vec[j] == A){
49
+ // sol++;
50
+ // return sol;
51
+ // }
52
+ // else if(vec[j] < A){
53
+ // sol++;
54
+ // A = A - vec[j];
55
+ // goto LOOP;
56
+ // }
57
+ // j--;
58
+ // }
59
+
60
+ // return 0;
61
+ // }
You can’t perform that action at this time.
0 commit comments