Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5704 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3523 |

@mantu_singh | 3510 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1156 |

@gurshehzadsingh | 676 |

@nithinreddy3210 | 642 |

@jha8768 | 577 |

@Run_for_life | 574 |

@divyagupta221100 | 557 |

@AkashLahoty | 551 |

@aayushdesai01 | 526 |

@riyakumaribkj | 526 |

@2017akku | 521 |

@amansinha74458 | 503 |

Complete Leaderboard |

Geek lost the password of his super locker. He remembers the number of digits **N** as well as the sum **S** of all the digits of his password. He know that his password is the largest number of **N** digits that can be made with given sum **S**. As he is busy doing his homework, help him retrieving his password.

**Example 1:**

Input:N = 5, S = 12Output:93000Explanation:Sum of elements is 12. Largest possible 5 digit number is 93000 with sum 12.

**Example 2:**

Input:N = 3, S = 29Output:-1Explanation:There is no such three digit number whose sum is 29.

**Your Task : **

You don't need to read input or print anything. Your task is to complete the function l**argestNumber()** which takes 2 integers **N** and **S** as input parameters and returns the password in the form of string, else return "-1" in the form of string.

**Constraints:**

1 ≤ N ≤ 10^{4}

0 ≤ S ≤ 9*10^{4}

**Expected Time Complexity** : O(N)

**Expected Auxilliary Space **: O(1)

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Largest number with given sum

...