Minimum Extra Points to visit all points, please suggest solution
Anonymous User
159

On Hackerearth hiring challange got the problem, wasn't able to solve it.
Please do suggest solution or path to it. Contest is over now.

Alice is playing a board game. She is given N points (Xi,Yi). She can start at any point and move up, down, left or right direction with any number of steps. But that way she can't visit all the points, she need some extra points to visit all points. Our task is to find the minimum number of extra points needed her to visit all the given points.

Example 1:
Input : [(1,2), (2,1)]
Output: 1
Explaination : she can't visit (2,1) from (1,2) , she needs extra points (1,1), so her path is (1,2) -> (1,1) -> (2,1)

Exmple 2:
Input : [(1,5), (1,3)]
Output : 0
Explaination : She can directly move left from (1,5) to (1,3) , so she dosen't need extra points to visit all points

Input format, like function to complete :

int getMinExtraPoints(int n, vector<vector<int>> points){

	//Your code here
	
}

Constrains :

1 <= N <=  50001 , number of points

1 <= x , y <= 50001, each points
x = point[0] , y = point[1] and point = points[i]

Hope u understand the problem satement, please let me know if you have any question.
Please do suggest some solution.

Comments (2)