Citadel OA | Birthday Card Collection | Citadel Online Assessment Question
HackerCards is a trendy new card game. Each type of HackerCard has a distinct ID number greater that or equals to 1, and the cost of each HackerCard equals its ID number. For example, HackerCard 1 costs 1, HackerCard 5 costs 5, and so on.
Leanne already has a collection started. For her birthday, Mike wants to buy her as many cards as he can, but they must cost less than or equals to his budget. He wants to buy one each of some cards she doesn't already have. If he has to make one choice among several, he will always choose the lowest cost option. Determine which cards he will buy.
Relevant Citadel OA Problems:
- Triplets
- Ways to Sum
- Consecutive Sum
- Disk Space Analysis
- Do They Belong?
- Global Maximum
- Initial Public Offering
- Inversions
- Portfolio Balances
- Prime Factor Visitation
- Profit Targets
- Sprint Training
- Throttling Gateway
- Birthday Card Collection
Input
collection
: the ID numbers of cards in Leanne's collectiond
: Mike's budget
Output
the ID's of the cards Mike will purchase, in ascending order
Examples
Example 1:
Input:
1arr = [2,4,5] 2d = 7
Output: 7
Explanation:
Leanne owns the cards in collection, and Mike has d = 7
to spend. He can purchase a maximum of 2 cards, cards 1 and 3, to add to her collection. Two other options he has are 1 and 6 (costs more) or 7 (fewer cards, costs more).
Constraints
1<=n<=10^5
1<=collection[i]<=10^9
1<=d<=10^9