Imposter
← Back to Diary

First diary entry

2025-08-08
diarygoals
  • Set up a dedicated Diary collection for daily progress.

  • Deployed the site preview and verified content collections.

  • Leetcode: Count Binary Substrings and Sliding Window Max

class Solution(object):
    def countBinarySubstrings(self, s):
        #, track the total count
        #track the last 0/1
        #track the current 0/1
        #we understand that it has to betogether
        #and that it is the minium number of 0/1
        #in that 0/1 group
        #to add to the count
        count = 0
        prev = 0
        curr = 1 #since we're starting at the 2nd one
        for i in range(1,len(s)):
            if s[i-1] != s[i]:
                #if the previous num isn't the same
                count += min(prev,curr)
                prev = curr
                #change number
                curr = 1
                #reset counter to 1
            else:
                curr += 1

        count += min(prev,curr)
        return count
class Solution:
    def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
        n = len(nums)
        ans = []
        queue = deque()

        for i in range(n):
        #keep monotonically decreasing
        #so we keep popping right until the right most number in the queue
        #is bigger than the current nums
        #so if the right most num is smaller than current nums
        #pop
            while queue and nums[queue[-1]] < nums[i]:
                queue.pop()
                
						#REMEMBER TO APPEND
            queue.append(i)
            
            #deal with window range
            #if the left most num in queue, is out of index
            if queue[0] + k  == i:
                queue.popleft()
            
            #eg. i = 3, 
            if i > k - 2:
                ans.append(nums[queue[0]])

        return ans
            #deal with starting the ans adding process when window is valid
← Back to All Entries