Stack (My Solution)
1 | class Solution { |
Remarks:
- TC: $O(n^2)$, SC: $O(n)$
Greedy
1 | class Solution { |
Remarks:
- TC: $O(n)$, SC: $O(1)$
- Key point: The farthest reachable position is non-decreasing
Dynamic Programming
1 | class Solution { |
- TC: $O(n^2)$, SC: $O(n)$