Two patrol boats guard a straight coastal channel that can be modeled as a number line. Boat A is anchored at position x and Boat B is anchored at position y. A distress beacon suddenly activates at position z. The instant the beacon activates, both boats depart and travel directly toward it along the line at the exact same constant speed.
Determine which boat reaches the beacon first. If Boat A gets there strictly before Boat B, report that Boat A wins. If Boat B gets there strictly before Boat A, report that Boat B wins. If both boats arrive at exactly the same moment, report a tie.
A single line containing three integers x, y, and z: the position of Boat A, the position of Boat B, and the position of the distress beacon, respectively.
Print a single integer: 1 if Boat A arrives first, 2 if Boat B arrives first, or 0 if they arrive at the same time.
Example 1
Input
2 10 5
Expected
1
Explanation
Boat A at position 2 is |2 - 5| = 3 units from the beacon, while Boat B at position 10 is |10 - 5| = 5 units away. Boat A is closer and arrives first, so the output is 1.
Example 2
Input
3 7 5
Expected
0
Explanation
Boat A is |3 - 5| = 2 units from the beacon and Boat B is |7 - 5| = 2 units away as well. The distances are equal, so both boats arrive at the same time and the output is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →