Greedy Algorithm / Math / Distance Calculation We are given three positions on a number line: · x: Position of Person 1. · y: Position of Person 2. · z: Position of Person 3 (the destination point). Person 1 and Person 2 both move towards Person 3 at the same speed, and we need to determine which person reaches Person 3 first. If both arrive at the same time, we return 0. Otherwise, we return 1 for Person 1 or 2 for Person 2, depending on who arrives first. The problem is quite simple and involves calculating the absolute distance from each person to Person 3 and comparing those distances. Calculate the Distance: We can calculate the distance from Person 1 to Person 3 as abs(x - z), and similarly, calculate the distance for Person 2 with abs(y - z). Comparison: If the distance for Person 1 is smaller than that of Person 2, return 1 (meaning Person 1 reaches first). If the distance for Person 2 is smaller than that of Person 1, return 2. If both distances are the same, return 0 (indicating they reach at the same time). This approach ensures an O(1) time complexity, as we only need to perform a few constant-time operations. Code Implementation: class Solution { public: int findClosest(int x, int y, int z) { int dist1 = abs(x - z); // Distance from Person 1 to Person 3 int dist2 = abs(y - z); // Distance from Person 2 to Person 3 if (dist1 Time Complexity: The time complexity of the solution is O(1) because we are performing constant-time operations. Space Complexity: The space complexity is O(1) as we are only using a fixed amount of extra space to store distances.