Hard
,Array
,Binary Search
1964. Find the Longest Valid Obstacle Course at Each Position
You want to build some obstacle courses. You are given a 0-indexed integer array obstacles
of length n
, where obstacles[i]
describes the height of the ith obstacle.
For every index i between 0
and n - 1
(inclusive), find the length of the longest obstacle course in obstacles
such that:
0
and i
inclusive.obstacles
.Return an array ans
of length n
, where ans[i]
is the length of the longest obstacle course for index i
as described above.
Example 1:
Example 2:
Example 3:
Constraints:
n
== obstacles.length
obstacles[i]
<= 107Yen-Chi ChenSun, May 7, 2023
學到很多,其實這題就是找最長非遞減子序列,看答案才恍然大悟,就是LIS的變形而已。
MarsgoatMon, May 8, 2023