Ctrl K

Walk Toward Each Other

Easy
You have an integer target and a starting number x that you pick yourself. A single move changes both numbers: x goes up or down by 1, and at the same time target goes up or down by 1. Using at most moves moves, you must make x and target equal (if they are equal from the start, no moves are needed). Return the largest starting x for which this is possible.
Example 1
target=5, moves=2 → 9

Start at 9. Move one: 9 → 8 and 5 → 6. Move two: 8 → 7 and 6 → 7. They match. From 10 or more, two moves are not enough.

Example 2
target=1, moves=1 → 3

From 3 in one move: 3 → 2 and 1 → 2.

Constraints
  • 1 ≤ target ≤ 50
  • 1 ≤ moves ≤ 50
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Number That Reads Both Ways EasyValue of a Roman Numeral EasyAdd One to a Digit Array EasySum of Binary Strings EasyWhole Square Root Easy
loading Python…
Input
target=5, moves=2
Expected
9

Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.