Prioritize Products Within Delivery Zones
Updated
Problem statement
You get three arrays of the same length. Each index i is one product request: zones[i] is its delivery zone, priorities[i] is its priority (High, Medium, or Low), and products[i] is its product ID. Every product ID is unique.
Return the product IDs grouped by zone. Put the zones in the order each one first shows up in zones. Inside one zone, list High requests first, then Medium, then Low. When two requests have the same zone and priority, keep them in their input order.
Function
prioritizeProducts(zones: String[], priorities: String[], products: String[]) → String[]Examples
Example 1
zones = ["west","east","west","east"]priorities = ["Low","High","High","Medium"]products = ["w-low","e-high","w-high","e-med"]return = ["w-high","w-low","e-high","e-med"]Zone west shows up first, so its products come first: w-high (High) before w-low (Low). Then comes east: e-high (High) before e-med (Medium). The answer is w-high, w-low, e-high, e-med.
Example 2
zones = ["z","z","z"]priorities = ["Medium","High","Medium"]products = ["m1","h","m2"]return = ["h","m1","m2"]All three requests are in zone z. The High product h goes first. The two Medium products keep their input order, so m1 comes before m2. The answer is h followed by those two.
Example 3
zones = ["b","a","b","c","a"]priorities = ["Low","Low","Medium","High","High"]products = ["bL","aL","bM","cH","aH"]return = ["bM","bL","aH","aL","cH"]Zones first show up in the order b, a, c. In zone b, bM (Medium) comes before bL (Low). In zone a, aH (High) comes before aL (Low). Zone c has only cH. The answer is bM, bL, aH, aL, cH.
Constraints
1 <= zones.length = priorities.length = products.length <= 100000.- Zones and product IDs are nonempty strings of letters, digits, or hyphens with length at most
30. - Product IDs are unique.
- Every priority is exactly
High,Medium, orLow.
More Amazon Onsite 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
- Optimal Account BalancingONSITE INTERVIEW · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Build a Pivot Table with TotalsSigma Computing · PHONE SCREEN
- Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Top K Largest Values from a StreamThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
- Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Banking System with Top ActivityCapital One · ONSITE INTERVIEWCapital One interview questions
Amazon interview experiences
- Amazon Experienced SDE Onsite Questions: 1 Experience
- Amazon SDE Onsite Interview Questions: 9 Experiences
- Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
- Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
- Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
- Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)