Day 326 of DSA
π LeetCode 3 β Longest Substring Without Repeating Characters
Variable Sliding Window:
Expand right.
Shrink left while duplicates exist.
Track max valid window length.
Revisiting this pattern. Good practice!
#DSA#LeetCode
Day 325 of DSA
π LeetCode 121 β Best Time to Buy and Sell Stock
Busy day, just revisited this one.
Track min_price and max_profit in one pass.
Simple approach, important pattern!
#DSA#LeetCode
Day 324 of DSA
π LeetCode 239 β Sliding Window Maximum
Revisited this one today.
Guessed Heap would help. Maintaining it and removing outdated elements was the tricky part.
Once the window movement clicked, the problem felt much easier!
#DSA#LeetCode
Day 323 of DSA
π LeetCode 76 β Minimum Window Substring
Variable Sliding Window + Frequency Array.
Track required character counts.
Expand right to find a valid window.
Shrink left to minimize it.
Store the smallest valid substring.
#DSA#LeetCode
Day 322 of DSA
π LeetCode 567 β Permutation in String
Fixed Window + Frequency Arrays.
The key:
Remove outgoing character.
Add incoming character.
Compare both frequency arrays.
No rebuilding the array for every window!
#DSA#LeetCode
Day 321 of DSA
π LeetCode 424 β Longest Repeating Character Replacement
Sliding Window + HashMap
Key formula:
window_size - max_freq <= k
Track frequencies, expand right, and shrink left when replacements exceed k.
Interesting pattern, but edge cases need more practice!
#DSA
Day 320 of DSA
π LeetCode 3 β Longest Substring Without Repeating Characters
Revised this after a while. Used pen and paper, worked through the pointers, and solved it myself!
Sliding Window + Set:
Expand right.
Remove duplicates from left.
Track max length.
#DSA#LeetCode
Day 319 of DSA
π LeetCode 121 β Best Time to Buy and Sell Stock
Busy day today. Focused on revising sliding window problems.
I'm realizing sliding window is one of my weaker topics. Understanding a solution is one thing; implementing it independently is another
#DSA#LeetCode
Day 318 of DSA
π LeetCode 1652 β Defuse the Bomb
Sliding Window + Circular Array:
Handle k == 0 separately.
Use modulo (% n) for circular indexing.
Calculate the initial window sum.
Slide the window by removing the outgoing value and adding the incoming one.
#DSA#LeetCode
Day 317 of DSA
π LeetCode 904 β Fruit Into Baskets
Variable-size Sliding Window:
Use a hashmap to track fruit frequencies.
Expand right to add fruits.
If distinct fruit types exceed 2, shrink from left.
Remove keys when their frequency reaches zero.
Track the maximum window len
Day 316 of DSA
π LeetCode 1456 β Maximum Number of Vowels in a Substring of Given Length
Fixed-size Sliding Window:
Count vowels in the first k characters.
Remove the outgoing character's contribution.
Add the incoming character's contribution.
Track the maximum count.
#DSA
Day 315 of DSA
π LeetCode 239 β Sliding Window Maximum
Brute force: Find the maximum in every window.
Optimized: Monotonic decreasing Deque.
Store indices, not values.
Remove expired indices.
Remove smaller elements from the back.
Front always holds the current maximum.
#DSA
Day 314 of DSA
π LeetCode 76 β Minimum Window Substring
Practised variable-size sliding window:
Expand right until the window is valid.
Track required character frequencies.
Shrink left while the window remains valid.
Keep the smallest valid window.
#DSA#LeetCode
Day 313 of DSA | LeetCode 567
Revised Permutation in String.
β Build frequency counts for s1
β Maintain a fixed-size window in s2
β Update counts as the window moves
β Compare both frequency arrays
β All 26 counts match? Return True
#LeetCode#Python#DSA
Day 312 of DSA | LeetCode 424
Revised Longest Repeating Character Replacement
The pattern:
β Expand the window
β Track character frequencies
β Maintain max_frequency
β If window_size - max_frequency > k, shrink
β Update maximum length
#LeetCode#Python#DSA#SlidingWindow
Day 311 of DSA | LeetCode 3
Revised Longest Substring Without Repeating Characters.
The pattern:
β left + right pointers
β Maintain a window using a set
β Duplicate found? Move left and remove characters
β Update maximum window length
#LeetCode#Python#DSA
Day 310 of DSA | LeetCode 121
Revised Best Time to Buy and Sell Stock.
Track two variables:
β minPrice β lowest price so far
β maxProfit β best profit so far
For every price:
β Calculate potential profit
β Update maximum profit
β Update minimum price
#LeetCode#Python
Day 309 of DSA | LeetCode 25
Revised Reverse Nodes in k-Group.
β Start with a dummy node
β Find the kth node
β Identify the next group
β Reverse the current group
β Reconnect the reversed group
β Repeat
Another linked list pattern to strengthen.
#LeetCode#Python#DSA
Day 308 of DSA | LeetCode 23
Revised Merge K Sorted Lists.
Using Divide and Conquer:
β Pick two sorted lists
β Merge them
β Put the result back
β Repeat until one list remains
A merge-sort-style approach built on the Merge Two Sorted Lists pattern.
#LeetCode#Python#DSA
Day 307 of DSA | LeetCode 146
Today was a reality check.
I literally forgot the LRU Cache implementation and had to look at the solution.
Haven't touched doubly linked lists in a while.
Tomorrow: revise and implement it again without looking.
#LeetCode#Python#DSA