This question evaluates understanding of linear interpolation, numerical reasoning with ordered 2D points, and input validation when computing values on a piecewise linear function.
You are given an ordered list of 2D points [(x1, y1), (x2, y2), ..., (xn, yn)]. Connecting each consecutive pair of points forms a piecewise linear function.
Given a target value target_x, return the corresponding y value on the function at that x-coordinate.
Assume:
x
.
target_x
may coincide with an existing point or fall between two adjacent points.
Clarify how you would handle edge cases such as:
target_x
outside the covered x-range
Example:
[(1, 2), (3, 6), (5, 4)]
target_x = 2
4
, because the point lies on the line segment between
(1, 2)
and
(3, 6)
.