Backtracking
1 | class Solution { |
Remarks:
- TC: $O(k^n)$,
nis the length of the array andkis 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.