Optimizing Jumping In Array With Greedy Algorithm
Greedy algorithm for jumping problem: Traverse array, find farthest index reachable with current jump, update range and increment count of jumps.
Problem /* TC: O(n), outer loop is just for checking if r<n-1, inner loop is doing the traversal for n elements This is greedy because in every iteration we are trying to find out the farthest index that we can jump to. example : nums = [2,3,1,1,4] for the index 0 , we can jump to index 1 or we can jump to index 2 So range for the first jump (jump = 1) becomes index: 1,2 from index 1 we can jump to index 2,3,4 ( if we jump to index 2 jump = 2, if we jump to index 3 jump = 2 and if we jump to index 4 jump =2, so we want to minimize the countOfJump and maximize the range of jump which is index...