You are given three of the four distinct vertices of an axis-aligned rectangle in the 2D plane. The sides of the rectangle are parallel to the x and y axes.
Given an array rectangle of three points, where rectangle[i] = [x_i, y_i], return the coordinates of the fourth (missing) vertex that completes the rectangle.
The rectangle has a non-zero area, and the answer is guaranteed to be unique.
Function Signature
def find_missing_vertex(rectangle: list[list[int]]) -> list[int]:
Rules
-
Each point is a list
[x, y]
. The three given vertices can appear in any order, and the missing vertex can be any of the four corners.
-
Return the missing vertex as a list
[x, y]
.
Constraints
-
len(rectangle) == 3
-
len(rectangle[i]) == 2
-
1 <= x_i, y_i <= 100
-
The given points are three distinct vertices of an axis-aligned rectangle with non-zero area.
Examples
Input: rectangle = [[1,1],[1,3],[3,1]]
Output: [3,3]
The three given vertices are (1,1), (1,3) and (3,1). The missing vertex must share x = 3 with (3,1) and y = 3 with (1,3), which gives (3,3).
Input: rectangle = [[2,5],[7,5],[2,8]]
Output: [7,8]
The x-values are 2, 7, 2, so the value 2 is already used by two corners and the missing corner has x = 7. The y-values are 5, 5, 8, so the missing corner has y = 8.
Input: rectangle = [[4,9],[10,2],[4,2]]
Output: [10,9]
The rectangle spans x in {4, 10} and y in {2, 9}. Its corners are (4,2), (4,9), (10,2) and (10,9), and only (10,9) is absent from the input.