The Find the Minimum and Maximum Number of Nodes Between Critical Points interview question involves a linked list. A "critical point" is a node that is either a local maximum (strictly greater than both its predecessor and successor) or a local minimum (strictly smaller than both). You need to find the minimum and maximum distance between any two distinct critical points in the list.
Microsoft and Meta ask this to test your proficiency with Linked List interview patterns. It requires you to maintain a window of three nodes (previous, current, next) while traversing the list. It evaluations your ability to handle edge cases, such as lists with fewer than two critical points, and your skill in tracking positions to calculate distances on the fly.
This is a Linked List Traversal with Position Tracking.
prev node pointer and look at curr.next.curr is a critical point by comparing prev.val, curr.val, and curr.next.val.firstCriticalIndex, lastCriticalIndex, and minDistance.minDistance = min(minDistance, currentIndex - lastCriticalIndex).lastCriticalIndex = currentIndex.firstCriticalIndex.maxDistance is simply lastCriticalIndex - firstCriticalIndex.List: 3 -> 1 -> 3 -> 3 -> 2 -> 2 -> 1
first = 1, last = 1.[-1, -1] if only one (or zero) critical point exists.For linked list problems that involve neighbors, use a prev pointer and always check if curr.next exists before entering the loop logic. This "Three-Node Window" is a standard technique for identifying local properties in sequences.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Split Linked List in Parts | Medium | Solve | |
| Reverse Nodes in Even Length Groups | Medium | Solve | |
| Odd Even Linked List | Medium | Solve | |
| Delete Node in a Linked List | Medium | Solve | |
| Insert into a Sorted Circular Linked List | Medium | Solve |