Practice Find the Minimum and Maximum Number of Nodes Between Critical Points
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Find the Minimum and Maximum Number of Nodes Between Critical Points
Problem Statement
A critical point in a linked list is defined as either a local maxima or a local minima. A node is a local maxima if the current node has a value strictly greater than the previous node and the next node. A node is a local minima if the current node has a value strictly smaller than the previous node and the next node. Note that a node can only be a local maxima/minima if there exists both a previous node and a next node. Given a linked list head, return an array of length 2 containing [minDistance, maxDistance] where minDistance is the minimum distance between any two distinct critical points and maxDistance is the maximum distance between any two distinct critical points. If there are fewer than two critical points, return [-1, -1].
Source: Find the Minimum and Maximum Number of Nodes Between Critical Points on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
head = [3,1]
[-1,-1]
# Example 2
head = [5,3,1,2,5,1,2]
[1,3]
# Example 3
head = [1,3,2,2,3,2,2,2,7]
[3,3]
Constraints
Related LeetCode Problems
Practice more problems similar to Find the Minimum and Maximum Number of Nodes Between Critical Points.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.