Group Jump Rope
InterviewTime limit1sMemory limit1024 MB
Given student heights, find the largest group that can line up so heights strictly rise toward the middle and then strictly fall, so no one faces someone as tall or taller.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
students want to jump rope together. They must stand in a single line, and each student faces one of the two ends of the line.
A student can get caught by the rope if someone in the direction they face is as tall as them or taller. Students want to jump as many times as possible, so they avoid situations where the rope can catch them. Each student lines up so that everyone in the direction they face is shorter than them.
Given the heights of the students, find the maximum number of students who can take part in the group jump rope. The person turning the rope is not included among the students.
Input
The first line contains the number of students . ()
The second line contains the heights of the students, separated by spaces. ()
Output
Print the maximum number of students who can take part in the group jump rope when the students are arranged so that no one can get caught on the rope.