Given the head of a singly linked list, determine the minimum and maximum distances between any two critical points.
A node is defined as a critical point if it is either a local maximum or a local minimum:
A node is a local maximum if its value is strictly greater than the value of the previous node and strictly greater than the value of the next node.
A node is a local minimum if its value is strictly smaller than the value of the previous node and strictly smaller than the value of the next node.
Return an integer array of length [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 [-1, -1].
Note: A node can only be considered a critical point if it has both a preceding node and a succeeding node.
Constraints:
The number of nodes in the list is in the range
Node.val
Given the head of a singly linked list, determine the minimum and maximum distances between any two critical points.
A node is defined as a critical point if it is either a local maximum or a local minimum:
A node is a local maximum if its value is strictly greater than the value of the previous node and strictly greater than the value of the next node.
A node is a local minimum if its value is strictly smaller than the value of the previous node and strictly smaller than the value of the next node.
Return an integer array of length [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 [-1, -1].
Note: A node can only be considered a critical point if it has both a preceding node and a succeeding node.
Constraints:
The number of nodes in the list is in the range
Node.val