I'm on a mission to master programming and tackle any coding challenge that comes my way. In this series, you'll find my daily journal entries, presented as simple bullet points. Nothing fancyโjust my honest thoughts and experiences from each day. So, please, no judgment! ๐
Join me as I document my tech journey in Bangalore. Let's dive in!
Day 6 (05/07/24)
Today's LeetCode Question was once again about linked lists 2058. Find the Minimum and Maximum Number of Nodes Between Critical Points
This one was also pretty simple. I just had to traverse the list and put the index of all the
critical points
in a separate array. Then, all that was left was to calculate the minimum and maximum difference between thecritical points.
# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def nodesBetweenCriticalPoints(self, head: Optional[ListNode]) -> List[int]: critical_points = [] prev = head curr = head.next i = 2 while curr.next: local_minima = (prev.val > curr.val and curr.val < curr.next.val) local_maxima = (prev.val < curr.val and curr.val > curr.next.val) if local_minima or local_maxima: critical_points.append(i) i += 1 prev = curr curr = curr.next if len(critical_points) < 2: return [-1, -1] result = [math.inf, critical_points[-1]-critical_points[0]] for i in range(len(critical_points)-1): result[0] = min(result[0], critical_points[i+1]-critical_points[i]) return result
Solved 2-3 questions related to monotonic stacks and sliding windows
Spent rest of my time playing League of Legends and watching Mirzapur.
I promise I'll be more productive tomorrow ๐ See ya!