Please enter your email address or userHandle.
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.
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.
For each test case, print the biggest number having maximum sum in new line.
1 <= T <= 100
1 <= N <= 1018
Input: n = 48
There are two numbers with maximum
digit sum. The numbers are 48 and 39
Since 48 > 39, it is our answer.
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.