Longest Sorted Library Section
Longest Sorted Library Section
HardArrays0% accepted
Priya manages Delhi's Central Library catalog where books are arranged by call numbers. She needs to identify continuous sections where books are strictly ordered—either all increasing or all decreasing—for inventory audits.
Approach
Find the length of the longest contiguous subarray that is sorted in either ascending or descending order.
Input
7
1 3 5 4 2 1 7
Output
4
More Arrays problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards