Practice Find the Longest Valid Obstacle Course at Each Position
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Hard#1964
LeetCode ProblemFind the Longest Valid Obstacle Course at Each Position
Problem Statement
For every index i, choose a subsequence of obstacles[0..i] that ends at i and whose heights are nondecreasing. Return the maximum possible length for each i. Chosen obstacles preserve their original order and equal heights are allowed.
Source: Find the Longest Valid Obstacle Course at Each Position on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
obstacles = [1,2,3,2]
Output
[1,2,3,3]
# Example 2
Input
obstacles = [2,2,1]
Output
[1,2,1]
# Example 3
Input
obstacles = [3,1,5,6,4,2]
Output
[1,1,2,3,2,2]
Constraints
n == obstacles.length
1 <= n <= 10^5
1 <= obstacles[i] <= 10^7
Related LeetCode Problems
Practice more problems similar to Find the Longest Valid Obstacle Course at Each Position.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.