Day 9 of #90DaysOfDSA: Merge Strings Alternately in Python | Piyush Kumar

🚀 #90DaysOfDSA Challenge – Day 9
Hi folks! 👋
I'm Piyush Kumar, and I'm back with my Day 9 progress in the 90 Days of DSA challenge.
Today, I focused on a popular string manipulation problem:
🔤 Merge Strings Alternately – Combine characters of two strings one by one, and append the rest if one is longer.
🧠 Problem Summary:
You're given two strings, word1
and word2
. The task is to merge them character by character. If one string is longer, just add the remaining characters to the end.
Here’s my optimized Python solution:
pythonCopyEditclass Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
merged = []
len1, len2 = len(word1), len(word2)
for i in range(min(len1, len2)):
merged.append(word1[i])
merged.append(word2[i])
merged.append(word1[i+1:] if len1 > len2 else word2[i+1:])
return ''.join(merged)
🔍 Key Learnings:
Efficient string iteration in Python
Using
min()
and slicing effectivelyClean, readable code matters!
💻 You can check out the full code here:
👉 Day 9 DSA Solutions GitHub
Let’s keep building the habit! See you on Day 10! 🚀
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!