Backtracking
1 | class Solution { |
Remarks:
- TC: $O(k^n)$,
n
is the length of the array andk
is the max value ofnums[i]
. -> Time Limit Exceeded
Greedy
1 | class Solution { |
Remarks:
- TC: $O(n)$, SC: $O(1)$
- Premise in the requirements:
The test cases are generated such that you can reach nums[n - 1].
, so we don’t care if the path can reach the end or not. What we only care is how far we can reach with less steps.