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
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code