Facebook Pixel

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:

Input & Output
Input
collection — the ID numbers of cards in Leanne's collection
d — Mike's budget
Output
the ID's of the cards Mike will purchase, in ascending order
Example
Input
arr = [2,4,5]
d = 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

Try it yourself

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro