Find the Longest Valid Obstacle Course at Each Position LeetCode solution in Python
1from bisect import bisect_right234class Solution:5def longestObstacleCourseAtEachPosition(self, obstacles: List[int]) -> List[int]:6longest, res = [], []7for i in range(len(obstacles)):8idx = bisect_right(longest, obstacles[i])9if idx == len(longest):10longest.append(obstacles[i])11else:12longest[idx] = obstacles[i]13res.append(idx + 1)14return res