Magicsheet logo

Find the Maximum Achievable Number

Easy
25%
Updated 8/1/2025

Asked by 4 Companies

Topics

Find the Maximum Achievable Number

What is this problem about?

The Find the Maximum Achievable Number coding problem is a straightforward mathematical challenge. You are given two integers, num and t. You can perform an operation tt times. In each operation, you can increase or decrease a number xx by 1 and simultaneously increase or decrease num by 1. A number xx is "achievable" if, after at most tt operations, xx and num can be made equal. Your goal is to find the maximum possible value of xx.

Why is this asked in interviews?

This "Easy" difficulty question is often used by companies like Microsoft and Amazon as a "warm-up" to test basic arithmetic reasoning and your ability to translate a word problem into a simple equation. It evaluations whether you can identify the most extreme case (where xx is as large as possible) and how the two numbers move towards each other. It’s a test of "Mathematical Intuition."

Algorithmic pattern used

This problem follows a basic Mathematical Pattern. To make xx as large as possible, you should decrease xx by 1 and increase num by 1 in every operation. After tt operations:

  • xx becomes xtx - t
  • num becomes num + t For them to be equal: xt=num+t    x=num+2tx - t = num + t \implies x = num + 2t.

Example explanation

num = 4, t = 1

  1. We want to find the max xx.
  2. Let's try x=6x = 6.
  3. Operation 1: Decrease xx to 5, increase num to 5.
  4. Now xx and num are equal.
  5. 4+2(1)=64 + 2(1) = 6. Result: 6.

Common mistakes candidates make

  • Overthinking: Trying to use a loop or simulation when a simple formula O(1)O(1) exists.
  • Misinterpreting the rule: Thinking only one number can be changed at a time.
  • Directional error: Increasing xx instead of decreasing it, which would make it move away from num.

Interview preparation tip

Always look for the "limit" cases in mathematical word problems. If you can perform an action tt times, what happens if you apply that action in the most extreme way possible? Most "achievable" or "reachability" problems have a linear relationship that can be derived in seconds.

Similar Questions