Hello Everyone!
I’m Somuya Khandelwal, here to share my updates from Day 4 of Week 4 in my competitive programming journey. Today, I worked on Sliding Window Problems, one of the most powerful techniques for solving challenges involving substrings and dynamic ranges. These problems required me to carefully manage window boundaries while using hashmaps to track elements efficiently.
What I Worked On Today
-
Substring With Concatenation of All Words (Hard Difficulty)
- Task: Find all starting indices of substrings in a string that are concatenations of all words in a given list exactly once.
-
Approach:
- Used a sliding window of fixed size (
len(word) * len(wordList)
) to traverse potential substrings. - Maintained a hashmap to track word counts and validate each window's contents.
- Used a sliding window of fixed size (
-
What I Learned:
- Sliding windows combined with hashmaps are incredibly effective for substring problems with specific constraints.
- Working with fixed-length windows helps avoid unnecessary recomputation and simplifies substring validation.
-
Minimum Window Substring (Hard Difficulty)
- Task: Find the smallest substring in a string that contains all characters of another string.
-
Approach:
- Used a dynamic sliding window to expand and shrink the range while ensuring all required characters were included.
- Maintained a hashmap to track character frequencies and validate the current window.
-
What I Learned:
- Sliding window techniques are ideal for problems that require optimizing ranges, especially when combined with frequency tracking.
- Balancing window expansion and contraction is critical for maintaining efficiency and correctness.
What I Learned Today
-
Dynamic Sliding Windows for Optimization:
- Problems like Minimum Window Substring reinforced how sliding windows can dynamically adjust to find optimal solutions for range-based challenges.
-
Hashmaps for Efficient Tracking:
- Both problems relied heavily on hashmaps to track word or character frequencies, showing their importance in solving substring-related tasks.
-
Balancing Expansion and Contraction:
- Expanding the window to include necessary elements and contracting it to minimize size requires careful implementation and debugging.
-
Handling Overlapping Conditions:
- Sliding window problems often involve complex conditions for when to expand or contract the window, making debugging a critical part of the process.
Reflections and Challenges
The Substring With Concatenation of All Words problem was the most challenging today. Managing the fixed-length substrings while ensuring word frequencies matched required multiple iterations to get right. Debugging overlapping conditions for validation was a bit tricky but very rewarding once I solved it. The Minimum Window Substring problem was equally engaging, as it pushed me to fine-tune my approach to handle dynamic window resizing efficiently.
Looking Ahead
On Monday, I’ll conclude the week with Hashmap Problems, tackling challenges like Contains Duplicate II and Longest Consecutive Sequence. These problems will help me further sharpen my skills in using hashmaps for efficient lookups and data organization.
Thank you for following along on my journey! I’m excited to continue learning and growing as I take on new challenges in competitive programming. Stay tuned for more updates!
Best regards,
Somuya
Top comments (0)