Question
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Determine if you are able to reach the last index.
Analysis
- Start with the recursive backtracking solution
- Optimize by using a memoization table (top-down[3] dynamic programming)
- Remove the need for recursion (bottom-up dynamic programming)
- Apply final tricks to reduce the time / memory complexity
Complexity
- Time: O(2^n) Space: O(n) recursion requires additional memory.
- Time: O(n^2) Space: O(2n)
- Time: O(n^2) Space: O(n)
- Time: O(n) Space: O(1)
Solution
1 |
enum Index { |
近期评论