Allocate Customers to Preferred Sites
Updated
Problem statement
There are preferredSite.length customers and capacity.length sites. Customer i requests exactly one site, preferredSite[i], and has integer priority priority[i]. Site s can accept at most capacity[s] customers.
For each site independently, accept the requesting customers with the highest priorities until its capacity is full. When priorities tie, accept the lower customer index first.
Return an array in customer-index order. The value at index i is the requested site when customer i is accepted, or -1 otherwise.
Function
allocatePreferredSites(preferredSite: int[], priority: int[], capacity: int[]) → int[]Examples
Example 1
preferredSite = [0,0,1,0]priority = [5,9,4,9]capacity = [2,1]return = [-1,0,1,0]Site 0 is asked for by customers 0, 1 and 3 with priorities 5, 9 and 9, and it has 2 places. Customers 1 and 3 have the highest priority, so they get it, and customer 0 gets -1. Site 1 is asked for only by customer 2 and has 1 place, so customer 2 gets site 1.
Example 2
preferredSite = [1,1,1]priority = [3,3,5]capacity = [0,1]return = [-1,-1,1]All three customers ask for site 1, which has 1 place. Customer 2 has the highest priority, 5, so customer 2 gets site 1. Customers 0 and 1 get -1. Site 0 has 0 places and nobody asks for it.
Constraints
1 ≤ preferredSite.length ≤ 200000priority.length == preferredSite.length1 ≤ capacity.length ≤ 2000000 ≤ preferredSite[i] < capacity.length0 ≤ priority[i] ≤ 10^90 ≤ capacity[s] ≤ preferredSite.length
More Yelp interview questions
Similar questions at other companies
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Select K Paired Indices for Maximum ScoreAmazon · ONSITE INTERVIEW
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
- Movie Schedule for Maximum EnjoymentC3.ai · ONSITE INTERVIEWC3.ai interview questions
- Minimum Refueling StopsUber · ONSITE INTERVIEWUber interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- Schedule Unit-Time Jobs for the Most ProfitScale AI · PHONE SCREENScale AI interview questions