Get Minimum Number of Unique Distribution Centers
Updated
Problem statement
A well-known consumer brand selling everyday products on Amazon is facing a supply issue due to daily changes in product demand. To manage this, Amazon has set up n distribution hubs, each labeled with a unique number from 1 to n. The demand on day i is dailyTrend[i] (days are 0-based), and n is the number of days, which is the length of dailyTrend.
Amazon decides which hub to use each day by comparing the current day’s demand with the previous day’s:
- If today’s demand is higher, a hub with a larger number than yesterday’s is chosen.
- If today’s demand is lower, a hub with a smaller number than yesterday’s is used.
- If today’s demand is the same, the same hub as yesterday is selected.
The total cost for the brand is based on how many different hubs are used over time. Your task is to find the minimum number of unique distribution hubs needed to handle the demand across all n days.
Function
getMinimumNumberOfUniqueDistributionCenters(n: int, dailyTrend: int[]) → int
Complete the function getMinimumNumberOfUniqueDistributionCenters in the editor.
getMinimumNumberOfUniqueDistributionCenters has the following parameters:
int n: the number of days, which is also the number of hubsint[] dailyTrend: the demand on each day
Returns
int: the minimum number of different hubs used over the n days
Examples
Example 1
n = 5dailyTrend = [10, 20, 30, 15, 10]return = 3Days are 0-based. Demand rises from day 0 to day 1 (10 to 20) and again to day 2 (20 to 30), so the hubs on days 0, 1 and 2 must be strictly increasing: at least 3 different hubs. The hub sequence [1, 2, 3, 2, 1] follows every rise and fall (demand then falls from 30 to 15 and from 15 to 10) and uses only the hubs 1, 2 and 3. Other valid choices exist, such as [3, 4, 5, 4, 3], which also uses 3 hubs. The answer is 3.
Constraints
1 <= n <= 10^5, wherenis the length ofdailyTrend1 <= dailyTrend[i] <= 10^9
More Amazon interview questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
Similar questions at other companies
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Server InvestmentRippling · OARippling interview questions
- Book Reading EveningsGoogle · OAGoogle interview questions
- Maximum Apples That Fit in a BoxVirtu Financial · OAVirtu Financial interview questions
- Minimum Project Bid CostNVIDIA · OANVIDIA interview questions
- Minimum AmountBelvedere Trading · OA
- Maximum Income from Asset TradingJefferies · OA
- Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions
- Economical TripAccenture · OAAccenture interview questions
- Best Time to Buy and Sell StockFlexTrade · OAFlexTrade interview questions