Longest Valid Obstacle
You are tasked with constructing obstacle courses. Given an integer array named obstacles of length n, where obstacles[i] represents the height of the ith obstacle, the goal is to find and print, for each index i between 0 and n−1 (inclusive), the length of the longest obstacle course in obstacles such that:
- You can select any number of obstacles between 0 and i (inclusive).
- You must include the ith obstacle in the course.
- The chosen obstacles must be placed in the same order as they appear in obstacles.
- Every obstacle (except the first) must be taller than or the same height as the obstacle immediately before it.
Print an array named ans of length n, where ans[i] represents the length of the longest obstacle course for index i as described above.
Ada AI
I want to discuss a solution
Help me solve this
Give more examples
What's wrong with my code?
How to use 'for loop' in javascript?
javascript (node 13.12.0)