Solving String Compression LeetCode 443 with Two Pointers

🚀 Day 59 of My Consistency Journey Today, I solved String Compression (LeetCode 443) — and honestly, it taught me a powerful lesson about thinking beyond brute force. 🔍 Key Learning: At first, I was tempted to use a HashMap to count frequencies, but that approach fails because this problem is about consecutive characters, not total frequency. 💡 Core Concept: 👉 Use Two Pointers (i & j) i → reads and counts characters j → writes compressed result 📌 Main Idea: "Group → Count → Write" Example: Input: a a a b c c Output: a3 b c2 ⚡ Important Insight: Handling counts like 12 or 15 means writing digits separately ('1', '2'), not as a single number. 🧠 What I Improved Today: Understanding in-place array modification Mastering two-pointer technique Writing optimized and clean logic Consistency is slowly turning confusion into clarity 💯 #Day59 #100DaysOfCode #Java #DSA #LeetCode #CodingJourney #PlacementPreparation #KeepLearning

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories