# Given an array of non-negative integers, you are initially positioned at the first index of the array.
To clarify the question, we are given a list/array of vals. Each val represents the MAX number of jumps it can take, meaning if the val is 4 it can stop after moving 2 steps and switch onto another val for jump.
To approach this problem we must realize that we need to keep track of
- Whether or not we can reach the end with current jump
- Is there a better jump in the path of our current jump? If so switch onto that jump instead.
- Where are we as we step forward in the current jump
Similar to the last problem, in this one we want to not only find out whether we can reach the end with the jumps but also return the minimum number of jump we could take. Simply put, we just got more greedy!
To approach this we would have to keep track of:
- the longest jump we can get as we step forward
- keep an variable for the max reaching distance, but not use it until it is necessary
- use the reach when the current longest cannot reach the end, means it’s time for a necessary jump
Simple and straight-forward problem, as we iterate through the list we just need to keep track of:
- the minimum price we can buy
- the maximum profit we will receive if we sell the holding stock with the current price
- update min price if there is a lower price in the list
- update max profit if we can make a better profit from any of the stock val
Ok now we can sell stock multiple times throughout the course of the list, but only can hold one stock at a time.
We can approach this by think of our actions as we iterate through the stock prices, instead of finding the buy-in and buy-out pair that wold give us max profit. Each time we iterated on a price, we should either sell or buy a stock.
This way we can ensure to make max profit throughout our investment journey.