FastPrepAllocate Customers to Preferred Sites
Problems/Allocate Customers to Preferred Sites

Allocate Customers to Preferred Sites

Yelp logoYelp● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report preserves the customer-to-site allocation theme and heap approach but omits the objective, capacities, and tie rules. The judged core task matches it at about 70%.

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 ≤ 200000
  • priority.length == preferredSite.length
  • 1 ≤ capacity.length ≤ 200000
  • 0 ≤ preferredSite[i] < capacity.length
  • 0 ≤ priority[i] ≤ 10^9
  • 0 ≤ capacity[s] ≤ preferredSite.length

More Yelp interview questions

  • Identify Broken Customer TransactionsPHONE SCREEN · Seen Nov 2021

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
All Yelp interview questionsSee Yelp hiring insights
Saved
class Solution {
    public int[] allocatePreferredSites(int[] preferredSite, int[] priority, int[] capacity) {
        // Write your code here.
    }
}
Checking account…