Evaluate Piecewise Linear Function
Company: Two Sigma
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This question evaluates understanding of piecewise linear interpolation, numerical reasoning, and the ability to handle ordered 2D point data and edge cases such as exact-coordinate matches.
Constraints
- points are ordered by strictly increasing x
- target_x is within range
Examples
Input: ([(0, 0), (10, 10)], 5)
Expected Output: 5.0
Explanation: Midpoint interpolation.
Input: ([(0, 2), (3, 8), (5, 8)], 3)
Expected Output: 8
Explanation: Exact point returns its y.
Input: ([(-1, 1), (1, 5)], 0)
Expected Output: 3.0
Explanation: Negative x range.
Input: ([(0, 0), (2, 3), (4, 0)], 3)
Expected Output: 1.5
Explanation: Interior segment.
Hints
- Binary-search the first point with x >= target_x.