Analysis:
two times traversal, first traversal ensure
dp[i] > dp[i-1]
ifrating[i] > rating[i-1]
and the reverse traversal, to ensuredp[i] > dp[i+1]
ifrating[i] > rating[i+1]
Time Complexity:
- O(n)
Space Complexity:
- O(n)
Code
1 | class Solution(object): |