Challenge: Largest Number with Given Number of Digits and Sum of Digits
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 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)
Sample Input
sumOfDigits = 20, numberOfDigits = 3
Sample Output
992
Note: If no number is possible for a combination of
SumOfDigits
andNumberOfDigits
no number is possible, then simply printNot Possible
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.