Jump Game II LeetCode solution in JavaScript
1/*2* Time Complexity : O(n)3* Space Complexity: O(1)4* */5var jump = function (nums) {6var jump = 0;7var prev = 0;8var max = 0;9for (var i = 0; i < nums.length - 1; i++) {10// Keep track of the maximum jump11max = Math.max(max, i + nums[i]);12// When we get to the index where we had our previous maximum jump, we increase our jump...13if (i === prev) {14jump++;15prev = max;16}17}1819return jump;20};