JuniorMath

Find the Maximum Achievable Number

Given two integers, num and t. A number x is achievable if it can become equal to num after applying the following operation at most t times:

  • Increase or decrease x by 1, and simultaneously increase or decrease num by 1.

Return the maximum possible value of x.

Example 1
Inputnum = 4, t = 1
Output6
Apply the operation once by decreasing the maximum achievable number by 1 and increasing num by 1, so 6 can become equal to 4.
Example 2
Inputnum = 3, t = 2
Output7
Apply the operation twice by decreasing the maximum achievable number by 1 and increasing num by 1 each time, so 7 can become equal to 3.

Constraints

  • 1 <= num, t <= 50

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate