codekofi
← All problems

Problem 3

Easy

1 · Worked examples

0 / 4

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 4 outputs correctly.

The accepted solution

1int solution(const vector<int>& nums) {
2
3 int lowest = INT_MAX;
4 int ans = 0;
5
6 for (int x : nums) {
7
8 if (x < lowest) {
9 lowest = x;
10 }
11
12 int gap = x - lowest;
13
14 if (gap > ans) {
15 ans = gap;
16 }
17 }
18
19 return ans;
20}

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.