Find the longest distance between coordinates
You are given two sets of coordinates:
1. A starting point represented by the array [x1, y1].
2. A destination point array with multiple coordinate pairs, such as [x2, y2, x3,y3, ..., xn, yn]. Your task is to find the destination point that has the longest distance from the starting point using the distance formula: [d=√(x2-21)2 + (y2 - y1)2]
Where:
■(x1, y1) is the starting point,
(x2, y2), (x3, y3), (x4, y4) are the destination points.
Special Conditions:
- If the starting point and any destination point are the same, the distance is 0. In this case, the output should be [-1, -1].
- If there are no destination coordinates provided, the output should be [-1, -1].
- If two or more destination points have the same maximum distance, the output should be [-1, -1].
Write a function findLongestDistancePoint that takes the starting coordinates and an array of destination coordinates, and returns the destination point that is farthest from the starting point, considering the special conditions.
Input:
- A coordinate array [x1, y1] representing the starting point. A coordinate array [x2, y2, x3, y3, xn, yn] representing multiple destination coordinates.
Output:
- The destination point (as an array [x, y]) that is farthest from the starting point, or [-1, -1] if the conditions are met.
Example 1:
Input:
Starting Point: [2, 2]
Destination Points: [2, 2, 2, 2]
Output:
[-1, -1]
Explanation:
Since the destination points are the same as the starting point, the distance is 8. As per the condition, the output is [-1, -1].
Example 2:
Input:
Starting Point: [0, 5]
Destination Points: [1, 2, 3, 4, 5]
Output:
[-1, -1]
Explanation:
There are no coordinates representing valid destination points (pairs of coordinates are missing), so the output is [-1, -1].
Example 3:
Input:
Starting Point: [1, 2]
Destination Points: [1, 2, 3, 4, 5, 6]
Output:
[5, 6]
Explanation:
The distance to each destination point is calculated:
Distance to [1, 2]: d = 0 (same point).
Distance to [3, 4]: d ≈ 2.83.
Distance to [5, 6]: d≈ 5.39.
The farthest point is [5, 6], so it is returned.