FastPrepPrioritize Products Within Delivery Zones
Problem · Array

Prioritize Products Within Delivery Zones

Learn this problem
MediumAmazon logoAmazonFULLTIMEONSITE INTERVIEW
See Amazon hiring insights

Problem statement

Each index describes one product request: zones[i] is its delivery zone, priorities[i] is High, Medium, or Low, and products[i] is its unique product ID.

Return the product IDs grouped by zone. Zones appear in the order of their first input occurrence. Within one zone, list High requests first, then Medium, then Low. Requests with the same zone and priority retain 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"]

West appeared first, so its High then Low products precede East's High then Medium products.

Example 2

zones = ["z","z","z"]priorities = ["Medium","High","Medium"]products = ["m1","h","m2"]return = ["h","m1","m2"]

The High product moves first while m1 remains before m2.

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"]

Zone order is b, a, c; priorities are applied independently inside each group.

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, or Low.

More Amazon problems

drafts saved locally
public String[] prioritizeProducts(String[] zones, String[] priorities, String[] products) {
  // write your code here
}
zones["west","east","west","east"]
priorities["Low","High","High","Medium"]
products["w-low","e-high","w-high","e-med"]
expected["w-high", "w-low", "e-high", "e-med"]
checking account