Day 6 in Bangalore

Day 6 in Bangalore

ยท

2 min read

๐Ÿ‘‹
Hi, I'm Pranay Sinha, a 3rd year B.Tech student with a keen interest in the tech industry and a passion for learning.

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 the critical 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!

ย