[LeetCode] Find the Maximum Achievable Number

2769. Find the Maximum Achievable Number

You are given two integers, num and t.

An integer x is called achievable if it can become equal to num after applying the following operation no more than t times:

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

Return the maximum possible achievable number. It can be proven that there exists at least one achievable number.

1
2
3
4
5
6
7
class Solution {
public:
int theMaximumAchievableX(int num, int t) {
return num + t * 2;
}
};

Author: Song Hayoung
Link: https://songhayoung.github.io/2023/07/09/PS/LeetCode/find-the-maximum-achievable-number/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.