FastPrepFastPrep
Problem Brief

Bounding Box from Coordinates

FULLTIMEOA

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:

  1. minX: the minimum x-value
  2. minY: the minimum y-value
  3. width: maxX - minX
  4. height: maxY - minY

Function Description

Complete the function boundingBoxFromCoordinates in the editor below.

boundingBoxFromCoordinates has the following parameter:

  1. int[][] coordinates: the list of points

Returns

int[]: [minX, minY, width, height].

1Example 1

Input
coordinates = [[2, 3], [5, 7], [1, 4]]
Output
[1, 3, 4, 4]
Explanation

The covered x-range is [1, 5] and the y-range is [3, 7], so the width and height are both 4.

2Example 2

Input
coordinates = [[0, 0]]
Output
[0, 0, 0, 0]
Explanation

A single point produces a zero-width, zero-height bounding box rooted at that point.

Constraints

Limits and guarantees your solution can rely on.

  • 1 <= coordinates.length <= 2 * 10^5
  • Each point contains exactly two integers.
  • -10^9 <= x, y <= 10^9
public int[] boundingBoxFromCoordinates(int[][] coordinates) {
    // write your code here
}
Input

coordinates

[[2, 3], [5, 7], [1, 4]]

Output

[1, 3, 4, 4]

Sign in to submit your solution.