🧠 Day 6 of My #90DaysOfDSA Challenge: Palindromes and Sliding Windows!

Piyush KumarPiyush Kumar
2 min read

📅 Date: May 26, 2025
🏷️ Tags: DSA, Python, LeetCode, Sliding Window, HashMap


👋 Hello Devs!

Welcome back to my #90DaysOfDSA journey. On Day 6, I focused on solving problems that involve string pairing and sliding window techniques — both of which are common patterns in coding interviews.


📌 Problem 1: Longest Palindrome by Concatenating Two Letter Words

🔗 LeetCode 2131

🔍 What I learned:

  • Using hashmaps to store frequency of words.

  • Forming palindromic structures by smartly pairing words and handling center palindromes like "aa", "gg", etc.

  • Only one self-palindrome word is allowed in the middle.

🛠️ Key Concepts:

  • HashMap / Counter

  • Reversible string logic

  • Greedy pairing

💻 My Code:

class Solution:
    def minSubArrayLen(self, target: int, nums: List[int]) -> int:
        left = 0
        total = 0
        min_len = float('inf')

        for right in range(len(nums)):
            total += nums[right]
            while total >= target:
                min_len = min(min_len, right - left + 1)
                total -= nums[left]
                left += 1

        return 0 if min_len == float('inf') else min_len

📁 View this code on GitHub


📌 Problem 2: Minimum Size Subarray Sum

🔗 LeetCode 209

🔍 What I learned:

  • How to use the sliding window pattern effectively to reduce time complexity from O(n²) to O(n).

  • Shrinking the window only when the current sum is greater than or equal to the target value.

  • Always track the minimum valid subarray length.

🛠️ Key Concepts:

  • Sliding Window

  • Two Pointers

  • Greedy optimization

💻 My Code:

class Solution:
    def twoSum(self, nums: List[int], target: int) -> List[int]:
        hashmap={}
        for i,n in enumerate(nums):
            diff=target-n
            if diff in hashmap:
                return [hashmap[diff],i]
            hashmap[n]=i

📁 View this code on GitHub


💡 Reflections from Today:

I realized that solving problems efficiently isn't just about getting the right answer — it's about finding patterns that work across many problems. Today’s takeaways:

  • Use Counter and [::-1] creatively when dealing with word symmetry.

  • Apply the sliding window technique to subarray problems where you're optimizing length or sum.


🚀 What’s Next?

Tomorrow, I plan to:

  • Solve more problems involving two pointers and prefix sums

  • Focus on problems tagged medium on LeetCode


🧵 Follow My Journey:

📌 GitHub: Piyush-Karn/DSA-Problems
🐦 Twitter: @CodeWithPiyush

Thanks for reading! See you on Day 7 👋


Would you like a Hashnode-friendly version with banner image links and code highlighting markdown? I can help format it for direct publishing too.

0
Subscribe to my newsletter

Read articles from Piyush Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Piyush Kumar
Piyush Kumar

Hey there! I’m Piyush Kumar, a curious mind on a mission to master Data Structures & Algorithms — one problem at a time. I’m not just solving questions; I’m building habits, debugging my thinking, and documenting the highs and lows of my coding grind. Whether it’s arrays at midnight, graph theory before coffee, or that satisfying “AC” moment after 17 failed attempts — I’m sharing it all openly. 📚 Currently on a 90-day DSA challenge, I post daily blogs and code logs that unpack: Real-world problem-solving strategies Patterns and techniques I learn (and unlearn) Honest reflections on growth, failure, and consistency Along the way, I’m also exploring how to apply AI to meaningful problems — because I believe in learning out loud and building in public. Let’s connect if you’re into: Open learning journeys 🚀 Problem-solving and pattern recognition 🧠 Building cool things with code ⚙️ ⚡ Follow along and let’s decode DSA — together!