You are given a collection of 2D points via the array points, where several points can share the same x-coordinate. Use these points to define a piecewise linear function. For each value in the array queries, compute the interpolated y-value according to these rules:
Return the results in the same order as the queries.
Constraints:
2 ≤ points.length ≤ 10^51 ≤ queries.length ≤ 10^5pointsExample 1:
points = [[1, 2], [1, 6], [3, 8], [5, 4]], queries = [1, 2, 4, 0, 6]
[6.0, 7.0, 6.0, -1.0, 2.0]
For x = 1, exact match, so return high(1) = 6.0. For x = 2, interpolate between (1, 6) and (3, 8) → 7.0. For x = 4, interpolate between (3, 8) and (5, 4) → 6.0. For x = 0, left extrapolation with (1, 2) and (3, 8) → -1.0. For x = 6, right extrapolation with (3, 8) and (5, 4) → 2.0.
Example 2:
points = [[0, 0], [2, 4]], queries = [1]
[2.0]
Example 3:
points = [[1, 2], [1, 5], [3, 9]], queries = [1, 2]
[5.0, 7.0]
Example 1
Input:
4
0.0 0.0
1.0 1.0
2.0 0.0
3.0 1.0
5
0.5
1.5
2.5
-1.0
4.0
Output:
0.5
0.5
0.5
-1.0
2.0
Example 2
Input:
2
0.0 0.0
10.0 10.0
3
0.0
10.0
5.0
Output:
0.0
10.0
5.0