Facebook | Onsite | intersecting lines

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-12-25Added By Anonymous
Source: Link

Company: Meta (Facebook)
Role: e3, e4
Interview Stage: Onsite
Location: unknown
Year: unknown

Original Post Content:

Question for a data scientist position:
Say you are given a list of tuples where the first element is the slope of a line and the second element is the intercept of a line.

Write a function to find which lines, if any, will intersect in the given range.
Is there a better than O(n^2) algo for this question?

Example

Input:

tuple_list = [(2, 3), (-3, 5), (4, 6), (5, 7)]
range = (0, 1)
Output:

intersections = [(2,3), (-3,5)]

Comments