Challenge: Find the Largest Number Possible
Given the number of digits and the sum of the digits, find the largest number that can be created.
We'll cover the following
Problem statement
A girl lost the key to her locker (note: The key is only numeric). She remembers the number of digits N
as well as the sum S
of all the digits of her password. She also knows that her password is the largest number of N
digits that can be possible with a given sum S
.
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 a list
Sample input
sum_of_digits = 20
number_of_digits = 3
Sample output
result = [9, 9, 2]
Note: If no number is possible for a combination of
sum_of_digits
andnumber_of_digits
, simply return[-1]
.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.