ByteByteGo logo
menuProblems List

Connect the Dots

Medium

Given a set of points on a plane, determine the minimum cost to connect all these points.

The cost of connecting two points is equal to the Manhattan distance between them, which is calculated as |x1 - x2| + |y1 - y2| for two points (x1, y1) and (x2, y2).

Example:

Input: points = [[1, 1], [2, 6], [3, 2], [4, 3], [7, 1]]
Output: 15

Constraints:

  • There will be at least 2 points on the plane.

You can practice coding exercises online by logging into bytebytego.com on your laptop.