Back to questions
Imagine you're a VP at FAANG, and you want to reward your team with gifts at the end of the year during Christmas time. You check in with stingy HR, and the best they could do is scrounge up a limited set of gift cards – each with different values and to various stores.
Each teammate has different expectations for their end-of-year gift – your Director expects a $1000+ gift card for something luxurious, while the new grad on your team would be thrilled with something as simple as a $10 gift card to Starbucks.
You can only give each person at most one gift card, and if a gift card doesn’t meet someone’s minimum expectation, it’s better not to give them one at all, as we definitely don't want to disappoint.
Find a way to satisfy as many teammates as possible by assigning each one a gift card that meets or exceeds their expectation.
Return the maximum number of teammates you can make satisfy.
Input:
Expectations = , Cards =
Output:
Explanation:
Input:
Expectations = , Cards =
Output:
Explanation:
To maximize the number of satisfied team members, we want to match lower-value gift cards with teammates who have lower expectations. This lets us reserve the higher-value gift cards for those who need more to feel satisfied, while still using each card effectively.
This approach is efficient because sorting takes and we only pass through each list once with the two pointers.
Here’s the implementation:
Instead of using a separate variable, we can simply return the as it will equal the number of satisfied teammates: