codekofi
← All problems

Problem 1

Easy35 XP

1 · Worked examples

0 / 4

Give it an input and say what you think comes back. It compiles and runs for real, so a wrong guess still shows you the answer — probe as much as you like. Only correct predictions count.

solution()
returns

2 · Which problem is it?

Locked until you have predicted 4 outputs correctly.

The accepted solution

1int solution(int n) {
2 int prev = 1;
3 int curr = 1;
4 for (int i = 1; i < n; i++) {
5 int next = prev + curr;
6 prev = curr;
7 curr = next;
8 }
9 return curr;
10}

Names have been stripped. The signature is the only clue you get for free. Compiled as C++20 with the standard headers and using namespace std; already in scope.