Biggest integer having maximum digit sum
Submissions: 564   Accuracy:

10.78%

  Difficulty: Basic   Marks: 1

Given a number N, the task is to find a number in range from 1 to N such that its sum is maximum. If there are several such numbers, print the biggest of them.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains a number N as input.

Output:
For each test case, print the biggest number having maximum sum in new line.

Constraints:
1<=T<=100
1<=N<=1018

Example:
Input:
2

90
48

Output:
89
48

Explanation:

Input: n = 48
Output: 48
There are two numbers with maximum
digit sum. The numbers are 48 and 39
Since 48 > 39, it is our answer.

** For More Input/Output Examples Use 'Expected Output' option **

Author: arun03


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.