Find the Maximum Achievable Number - Problem

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:

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

Return the maximum possible value of x.

Input & Output

Example 1 — Basic Case
$ Input: num = 4, t = 1
Output: 6
💡 Note: Start with x = 6. Operation: x decreases to 5, num increases to 5. Now x = num = 5. Maximum achievable x was 6.
Example 2 — Multiple Operations
$ Input: num = 3, t = 2
Output: 7
💡 Note: Start with x = 7. After 2 operations moving optimally: x can decrease to 5, num can increase to 5. Maximum achievable x was 7.
Example 3 — Zero Operations
$ Input: num = 5, t = 0
Output: 5
💡 Note: No operations allowed, so x must equal num = 5 from the start. Maximum x is 5.

Constraints

  • 1 ≤ num ≤ 1000
  • 1 ≤ t ≤ 1000

Visualization

Tap to expand
Find Maximum Achievable Number: num=4, t=1Inputnum = 4, t = 1ProcessStrategyStart: x=6, num=4After 1 op: x=5, num=5ResultOutputMaximum x = 6Given valuesBoth values change by ±1Formula: num + 2*tKey Insight: Both x and num can move in opposite directionsTo maximize x: increase x by t, decrease num by t simultaneously
Understanding the Visualization
1
Input
Given num=4, t=1 operations allowed
2
Strategy
Start x high, move x and num toward each other
3
Output
Maximum possible x = 6
Key Takeaway
🎯 Key Insight: Both numbers can move simultaneously in opposite directions to maximize their separation
Asked in
Google 15 Amazon 12 Microsoft 8
15.0K Views
Medium Frequency
~5 min Avg. Time
450 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen