Problem · Array
Bounding Box from Coordinates
You are given a non-empty list of 2D points coordinates, where each point is [x, y].
Return four integers describing the smallest axis-aligned bounding box that covers every point:
minX: the minimum x-valueminY: the minimum y-valuewidth:maxX - minXheight:maxY - minY
Complete the function boundingBoxFromCoordinates in the editor below.
boundingBoxFromCoordinates has the following parameter:
int[][] coordinates: the list of points
Returns
int[]: [minX, minY, width, height].
Examples
01 · Example 1
coordinates = [[2, 3], [5, 7], [1, 4]] return = [1, 3, 4, 4]
The covered x-range is [1, 5] and the y-range is [3, 7], so the width and height are both 4.
02 · Example 2
coordinates = [[0, 0]] return = [0, 0, 0, 0]
A single point produces a zero-width, zero-height bounding box rooted at that point.
Constraints
1 <= coordinates.length <= 2 * 10^5- Each point contains exactly two integers.
-10^9 <= x, y <= 10^9
More Upstart problems
public int[] boundingBoxFromCoordinates(int[][] coordinates) {
// write your code here
}
coordinates[[2, 3], [5, 7], [1, 4]]
expected[1, 3, 4, 4]
checking account