codekofi
← All problems

Problem 78

Easy

1 · Worked examples

0 / 3

Type an input and write what you think is the output . Each problem is converted to Web Assembly, so any possible input will show the corresponding output. Only correct predictions count.

solution()
returns

2 · Which problem is it?

Locked until you have predicted 3 outputs correctly.

The accepted solution

1vector<int> solution(vector<int> digits) {
2
3 int n = digits.size();
4
5 for (int i = n - 1; i >= 0; i--) {
6
7 if (digits[i] < 9) {
8 digits[i]++;
9 return digits;
10 }
11
12 digits[i] = 0;
13 }
14
15 digits.insert(digits.begin(), 1);
16
17 return digits;
18}

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.