Challenge: Find the Largest Number
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
and 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 the given sum S
.
Implement a function that helps her retrieve her key.
Input
The inputs are the number of digits and the sum of those digits.
Output
The output prints the largest number that can be created (or the key).
Sample input
number_of_digits = 3, sum_of_digits = 20
Sample output
992
Note: If no number is possible for a combination of
sum_of_digits
andnumber_of_digits
, then simply printNone
.
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.