codekofi
← All problems

Problem 3

Easy30 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(const vector<int>& nums) {
2 int lowest = INT_MAX;
3 int best = 0;
4 for (int x : nums) {
5 if (x < lowest) lowest = x;
6 if (x - lowest > best) best = x - lowest;
7 }
8 return best;
9}

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.