Subsequence with the Largest Maximum-Minimum Difference
InterviewTime limit0.5sMemory limit256 MB
Given a sequence, find the shortest contiguous segment whose max minus min equals the largest such difference over all segments.
- Level
Medium5 of 10
- Topics
- Two pointers, Array, Greedy, Implementation
- Solved
- No attempts yet
Problem
A subsequence of a sequence is a sequence obtained by taking some consecutive terms of the sequence and listing them in their original order. (This is not the usual definition of a subsequence.) Given a sequence of length , find the length of the shortest subsequence of whose value of (maximum in the subsequence) - (minimum in the subsequence) is the largest possible.
Input
The first line gives . ()
The next line gives numbers separated by spaces, where the -th number is . ()
Output
Print a single integer, the answer to the problem.