Max Value of Equation
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given points, where points[i] = [x_i, y_i], sorted by x in **strictly increasing** order, and an integer k.
Choose two indices i < j with x_j - x_i <= k and maximize the value y_i + y_j + |x_i - x_j|. Return that maximum value. The input guarantees that at least one valid pair exists.
An O(n^2) scan over all pairs is too slow for the largest inputs; aim for O(n).
Examples
Constraints
- `2 <= points.length <= 10^5`
- `-10^8 <= x_i, y_i <= 10^8`
- `0 <= k <= 2 * 10^8`
- `x_i < x_{i+1}`
- At least one pair satisfies `x_j - x_i <= k`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.