Find Closest Person

You are given three integers `x`, `y` and `z`, the positions of three people on a number line: person 1 is at `x`, person 2 is at `y`, and person 3 is at `z` and does not move. Persons 1 and 2 walk toward person 3 at the same speed. Return `1` if person 1 reaches person 3 first, `2` if person 2 arrives first, and `0` if they arrive at the same time.

30:00

Find Closest Person
easy
Free written solution
Topics
Companies

You are given three integers x, y and z, the positions of three people on a number line: person 1 is at x, person 2 is at y, and person 3 is at z and does not move.

Persons 1 and 2 walk toward person 3 at the same speed. Return 1 if person 1 reaches person 3 first, 2 if person 2 arrives first, and 0 if they arrive at the same time.

Example 1:
Input: {"x":2,"y":7,"z":4}
Output: 1
Constraints:
  • 1≤x,y,z≤1001 \leq x, y, z \leq 100

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"x":2,"y":7,"z":4}

Person 1 stands at 2, person 2 at 7, and person 3 waits at 4. Both walkers move at the same speed.

3
1
2

2

7

4

step 0: solid trail = walked, dashed = still to go

person 1

d = ?

2 to go

person 2

d = ?

3 to go

Variables
VariableValue
x2
y7
z4
DepthFunction Call
Stack empty
0/5