DEV Community

Ben Pereira
Ben Pereira

Posted on

Leetcode — 2769. Find the Maximum Achievable Number

This is an easy problem with description being:

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

Increase or decrease the number by 1, and simultaneously increase or decrease num by 1.

Return the maximum achievable number after applying the operation at most t times.

This problem is more of text interpretation than anything else. Basically you have a number and you have a number of operations (t). Every time an operation runs it increases or decreases number by 1.

Maximum achievable number would be the biggest number after all t operations (that increase/decrease by one).

To summarize, to solve this you need basically multiply the amount of operations by two (since there is two operations inside the main one) and sum with num.

class Solution {
    public int theMaximumAchievableX(int num, int t) {
        return num + 2 * t;
    }
}
Enter fullscreen mode Exit fullscreen mode

Runtime: 1 ms, faster than 100.00% of Java online submissions for Find the Maximum Achievable Number.

Memory Usage: 41.3 MB, less than 63.18% of Java online submissions for Find the Maximum Achievable Number.


That’s it! If there is anything thing else to discuss feel free to drop a comment, if I missed anything let me know so I can update accordingly.

Until next post! :)

Top comments (0)