Challenge: Find the Largest Number Possible

Find the largest number that can be created from a set of digits and their sum.

Problem statement

Suppose a girl lost the key to her locker (the key is only numeric). She remembers the number of digits NN as well as the sum SS of all the digits of her password. She also knows that her password consists of the largest possible digits that add up to the sum of SS.

Implement a function that would help her retrieve her key.

Input

The number of digits and the sum of those digits.

Output

The largest number that can be created (or the key) as an array.

Sample input

sumOfDigits = 20;
numberOfDigits = 3;

Sample output

result = {9, 9, 2};

Note: If no number is possible for a combination of sumOfDigits and numberOfDigits, simply return [-1].

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.