DEV Community

Somuya Khandelwal
Somuya Khandelwal

Posted on

DAY 19 Mastering Sliding Window Problems

Hello Everyone!

I am Somuya Khandelwal, and I’m excited to share my progress from Day 4 of Week 4 in my competitive programming journey. Today’s focus was on Sliding Window Problems, a powerful technique for solving substring-related challenges and optimizing dynamic ranges in arrays. These problems required careful management of window boundaries and efficient use of hashmaps.


What I Worked On Today

  1. Substring With Concatenation of All Words (Hard Difficulty)

    • Find all starting indices of substring(s) in a given string that is a concatenation of each word in a list exactly once.
    • Approach:
      • Used a sliding window with a fixed size (len(word) * len(wordList)) to iterate through possible substrings.
      • Maintained a hashmap to track word frequencies and validate each substring.
    • What I Learned:
      • Sliding windows combined with hashmaps are ideal for substring problems with constraints on content and order.
      • Efficient substring generation avoids recomputation by leveraging fixed-length word sizes.
  2. Minimum Window Substring (Hard Difficulty)

    • Find the smallest substring in a string that contains all characters of another string.
    • Approach:
      • Used a sliding window to dynamically expand and contract the range, ensuring all required characters were included.
      • Maintained a hashmap to track character counts and validate window contents.
    • What I Learned:
      • Sliding window techniques excel in finding optimal ranges when combined with hashmap-based frequency tracking.
      • Efficiently managing shrinking windows ensures the solution remains optimal.

What I Learned Today

  1. Efficient Sliding Window Techniques:

    • Problems like Minimum Window Substring demonstrated how dynamic window resizing can be used to solve range-based challenges optimally.
  2. Hashmaps for Frequency Tracking:

    • Both problems required using hashmaps to track character or word frequencies, highlighting their importance in substring-related problems.
  3. Balancing Window Expansion and Contraction:

    • Expanding the window to include all necessary elements and contracting it to minimize the size was key in both problems.
  4. Debugging Complex Conditions:

    • Sliding window problems often involve multiple conditions for expansion and contraction, requiring thorough debugging and careful boundary management.

Reflections and Challenges

The Substring With Concatenation of All Words problem was particularly challenging due to the need for fixed-length substring generation and precise frequency matching. Debugging the overlapping conditions for substring validation took significant effort but ultimately helped me appreciate the power of sliding windows. The Minimum Window Substring problem was equally rewarding, as it required balancing multiple constraints while ensuring optimality.


Looking Ahead

On Monday, I’ll wrap up the week with Hashmap Problems, including Contains Duplicate II and Longest Consecutive Sequence. These tasks will further test my ability to manage and optimize data storage for efficient lookups.

Thank you for following along on my journey! Stay tuned for more updates and insights as I continue tackling competitive programming challenges.

Top comments (0)