Leetcode 2058 - Find the Minimum and Maximum Number of Nodes Between Critical Points [5/7/24]

Поделиться
HTML-код
  • Опубликовано: 3 июл 2024
  • Time Taken: ~20 mins
    Tag: LeetCode Medium
    Concept: Linked List
    High-level ideas:
    1. Store a vector of critical points:
    We do so by keep track of node before ("parent") and node after the current node we are at, as well as “index”.
    Every time we move forward by a node in the iteration, we update current pointer (“head”), value of previous node (“parent”).
    Stop iteration when next node is null (meaning we have reached last node, which is not considered).
    2. From vector of critical points:
    Derive maximum difference in distance from first and last value (vector is sorted)
    Derive minimum difference by considering consecutive values in vector.

Комментарии •