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.
Locked until you have predicted 4 outputs correctly.
| 1 | int 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.