Find the Minimum and Maximum Number of Nodes Between Critical Points
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
In a linked list, a **critical point** is a node that has both a previous and a next node and is either a **local maximum** (strictly greater than both neighbors) or a **local minimum** (strictly smaller than both neighbors). The first and last nodes are never critical.
Given the head of a linked list, return a two-element array [minDistance, maxDistance], where minDistance is the smallest distance between any two distinct critical points and maxDistance is the largest. Distance is the difference of the nodes' positions in the list.
If the list has fewer than two critical points, return [-1, -1].
Examples
Constraints
- 2 <= number of nodes <= 10^5
- 1 <= Node.val <= 10^5
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.