java.lang.Object
g2701_2800.s2769_find_the_maximum_achievable_number.Solution

public class Solution extends Object
2769 - Find the Maximum Achievable Number.<p>Easy</p> <p>You are given two integers, <code>num</code> and <code>t</code>.</p> <p>An integer <code>x</code> is called <strong>achievable</strong> if it can become equal to <code>num</code> after applying the following operation no more than <code>t</code> times:</p> <ul> <li>Increase or decrease <code>x</code> by <code>1</code>, and simultaneously increase or decrease <code>num</code> by <code>1</code>.</li> </ul> <p>Return <em>the maximum possible achievable number</em>. It can be proven that there exists at least one achievable number.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> num = 4, t = 1</p> <p><strong>Output:</strong> 6</p> <p><strong>Explanation:</strong></p> <p>The maximum achievable number is x = 6; it can become equal to num after performing this operation:</p> <p>1- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.</p> <p>It can be proven that there is no achievable number larger than 6.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> num = 3, t = 2</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong></p> <p>The maximum achievable number is x = 7; after performing these operations, x will equal num:</p> <p>1- Decrease x by 1, and increase num by 1. Now, x = 6 and num = 4.</p> <p>2- Decrease x by 1, and increase num by 1. Now, x = 5 and num = 5.</p> <p>It can be proven that there is no achievable number larger than 7.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= num, t <= 50</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • theMaximumAchievableX

      public int theMaximumAchievableX(int num, int t)