Solved 2058 Find Min Max Nodes Between Critical Points in Linked List

🚀 Day 88 of #100DaysOfCode Solved 2058. Find the Minimum and Maximum Number of Nodes Between Critical Points 🔗 🧠 Key Insight: A node is a critical point if: 🔺 It is a local maxima → greater than both neighbors 🔻 It is a local minima → smaller than both neighbors ⚙️ Approach (Single Pass + Index Tracking): 1️⃣ Traverse the linked list while keeping track of: • prev, curr, next • current index i 2️⃣ Identify critical points: ✔️ curr > prev && curr > next ✔️ curr < prev && curr < next 3️⃣ Store their indices 4️⃣ If total critical points < 2 → return [-1, -1] 5️⃣ Otherwise compute: ✅ Minimum distance → between consecutive critical points ✅ Maximum distance → between first & last critical point ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(k) (critical points count) #100DaysOfCode #LeetCode #DSA #LinkedList #ProblemSolving #CodingJourney

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories