AmazonOA #230
Get Minimum Number of Unique Distribution Centers
Estimated MediumJudge-ready
Topics (AI-labelled)In-place ArraysGreedy
On day i, choose a center numbered 1..n. If demand is higher than on the previous day, the center number must be strictly higher; if demand is lower, it must be strictly lower; if demand is equal, the same center must be used. Minimize the number of distinct centers used over all days.
Input
The first line contains n; the second line contains each day's demand. The original text had no numeric bounds; this site uses 1≤n≤200000, 0≤demand≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
5
10 20 30 15 10
Output:
3
Example 2
Input:
4
1 2 2 3
Output:
3
Example 3
Input:
2
5 5
Output:
1
Example notes
The answers are 3, 3 and 1. Equal demands do not interrupt a continuing rising constraint.
Editorial
Loading solution…