Skip to content

Practice Find Closest Person

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3516
LeetCode Problem

Find Closest Person

Problem Statement

People 1 and 2 start at positions x and y on a number line and move at the same speed toward Person 3, who remains at z. Return 1 if Person 1 arrives first, 2 if Person 2 arrives first, or 0 if they arrive together.

Source: Find Closest Person on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
x = 2, y = 7, z = 4
Output
1

# Example 2

Input
x = 2, y = 5, z = 6
Output
2

# Example 3

Input
x = 1, y = 5, z = 3
Output
0

Constraints

1 <= x, y, z <= 100

Related LeetCode Problems

Practice more problems similar to Find Closest Person.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.