# Leetcode 55 Jump Game

## Approach

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

## Implementation

https://leetcode.com/problems/jump-game/

# Leetcode 45 Jump Game II

## Approach

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

## Implementation

https://leetcode.com/problems/jump-game-ii/

# Leetcode 121 Best time to buy stock

## Approach

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