https://leetcode.com/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points/



Memory Limit Exceeded


```python
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next

from itertools import combinations
class Solution:
    def nodesBetweenCriticalPoints(self, head: Optional[ListNode]) -> List[int]:
        #08:07
        index = 0
        last_node_value = None
        node = head
        critical_index_list = []
        while node:
            if (last_node_value==None):
                pass
            else:
                if (node.next):
                    if (last_node_value < node.val > node.next.val):
                        critical_index_list.append(index)
                    if (last_node_value > node.val < node.next.val):
                        critical_index_list.append(index)
            index += 1
            last_node_value = node.val
            node = node.next
        #print(critical_index_list)
        if (len(critical_index_list) == 0 or len(critical_index_list) == 1):
            return [-1, -1]
        distances = [abs(a-b) for a,b in combinations(critical_index_list, 2)]
        distances *= 2
        distances.sort()
        #print(distances)
        return [distances[0], distances[-1]]
        #8:20
```
