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.
Locked until you have predicted 3 outputs correctly.
| 1 | int solution(const vector<int>& nums) { |
| 2 | |
| 3 | int n = nums.size(); |
| 4 | |
| 5 | int jumps = 0; |
| 6 | int edge = 0; |
| 7 | int farthest = 0; |
| 8 | |
| 9 | for (int i = 0; i + 1 < n; i++) { |
| 10 | |
| 11 | farthest = max(farthest, i + nums[i]); |
| 12 | |
| 13 | if (i == edge) { |
| 14 | jumps++; |
| 15 | edge = farthest; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | return jumps; |
| 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.