Minimum Cost to Connect All Points Problem Statement

Given an array COORDINATES representing the integer coordinates of some points on a 2D plane, determine the minimum cost required to connect all points. The cost to connect two points, (x1, y1) and (x2, y2), is defined by their Manhattan distance: |x1 - x2| + |y1 - y2|.

Input:

The first line of input contains an integer 'T' representing the number of test cases. The first line of each test case contains an integer ‘N’ representing the number of points in the ‘COORDINATES’ array. The next ‘N’ lines of each test case contain two space-separated integers representing the ‘X’ and ‘Y’ coordinates of a point.

Output:

For each test case, output a single integer denoting the minimum cost to connect all points. Each test case's result should be printed on a new line.

Example:

Consider the input:

2
3
0 0
2 2
3 10
4
0 0
10 10
20 20
5 5

Expected output:

12
30

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 1000
  • 10^{-6} ≤ X, Y ≤ 10^{6}
  • All points are distinct.

Note:

You do not need to implement input/output handling. The focus should be on the function logic to compute the minimum cost.

Ensure all points are connected with one simple path only, as defined by path terminology in graph theory.

AnswerBot
4mo

The problem involves finding the minimum cost to connect all points on a 2D plane using Manhattan distance.

  • Create a function that calculates the Manhattan distance between two points.

  • Implement a funct...read more

whistlingbeaver
5mo
Hello sir
Help your peers!
Select
Add answer anonymously...

Oracle Application Developer interview questions & answers

An Application Developer was asked 9mo agoQ. Given the heads of two singly linked-lists headA and headB, return the node at w...read more
An Application Developer was asked 10mo agoQ. How do you calculate area using coordinates?
An Application Developer was asked 10mo agoQ. Given a set of points in the xy-plane, find the minimum area of a square that co...read more

Popular interview questions of Application Developer

An Application Developer was asked 10mo agoQ1. How do you calculate area using coordinates?
An Application Developer was asked 10mo agoQ2. Given a set of points in the xy-plane, find the minimum area of a square that co...read more
An Application Developer was asked 11mo agoQ3. Given an array of integers, find the maximum length of a subarray with a given s...read more
Oracle Application Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits