Christmas mission: Distribute gifts #3
Description:
When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
Description:
Christmas is coming soon. Santa Claus is ready for the gift, he will give the gifts to the children. Of course, the gift of Santa Claus is not enough to give all the children, he needs to make a choice. Your task is to help Santa make the best choice:
Suppose Santa Claus has n
gifts, and each child has a wish (the number of gifts to be obtained). Provides an array of integers wishes
representing all the wishes. Like this:
n = 20
wishes = [2,4,3,5,6,10,12,100]
The result is a possible combination (an array) that happens to be able to distribute all of the gifts. In accordance with the above example, the results can be:
[2,3,5,10] or [4,6,10] or [2,6,12] or...
You should return one of them.
If there is no valid result, return a string "Mission Failed!"
Note:
n
and all elements ofwishes
always be positive integers.
Some Examples
distributeGifts(20,[2,4,3,5,6,10,12,100])
Can return [2,3,5,10] or [4,6,10] or [2,6,12]...
distributeGifts(20,[10,10,40,100])
hould return [10,10]
distributeGifts(20,[20,40,100])
hould return [20]
distributeGifts(20,[30,40,100])
hould return "Mission Failed!"
Similar Kata:
Stats:
Created | Dec 12, 2016 |
Published | Dec 14, 2016 |
Warriors Trained | 278 |
Total Skips | 16 |
Total Code Submissions | 717 |
Total Times Completed | 101 |
JavaScript Completions | 57 |
Haskell Completions | 26 |
Python Completions | 25 |
Total Stars | 6 |
% of votes with a positive feedback rating | 92% of 33 |
Total "Very Satisfied" Votes | 29 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 4 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 6 kyu |