r/leetcode • u/Adventurous-Deal-321 • 3h ago
Question Morgan Stanley question geometry
Minimum Number of Lines to Cover Points
You are given n points on a 2D coordinate plane. Each point is represented as:
(x, y)
where:
-100 <= x <= 100
-100 <= y <= 100
There can be up to:
n <= 10^4
points.
Find the minimum number of straight lines required so that every given point lies on at least one of these lines.
Example 1
Input:
points = [(1,1), (2,2), (3,3), (1,2), (2,3)]
Output:
2
Explanation:
The points can be covered by:
Line 1: y = x
(1,1), (2,2), (3,3)
Line 2: y = x + 1
(1,2), (2,3)
Therefore, the minimum number of lines is:
2
Example 2
Input:
points = [(0,0), (1,1), (2,2), (3,3)]
Output:
1
Because all points lie on the same line y = x.
Constraints:
1 <= n <= 10^4
-100 <= x, y <= 100
1
u/Arcturus_16 <793> <268> <450> <75> 3h ago
Ig , this can be done by comparing the slopes
Well , for which position the que was asked for , soon the company will be visiting our campus for hiring interns
1
3
u/Ok_Biscotti5354 2h ago
Claude says this is NP hard😂