Apartment Housemate Preferences
Problem statement
Apartment i has rooms[i] rooms, and each room holds one person, so the apartment can house at most rooms[i] people. Person p either wants housemates (wantsHousemates[p] is true) or wants to live alone (false).
Every person must be placed in exactly one apartment; apartments may stay empty. The rooms are enough in total for everyone, yet some people may end up in an arrangement they did not ask for:
Examples
Example 1
rooms = [2,1,4]wantsHousemates = [true,false,true]return = 3Put person 1 (who wants to live alone) in the 1-room apartment, and persons 0 and 2 (who both want housemates) together in the 2-room apartment. The 4-room apartment stays empty. All 3 people get what they want.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.