Java String Compression Challenge - Two Pointers

100 Days of Coding Challenge – Day 17 📌 Problem: String Compression 💻 Language: Java 🧠 Concept Used: Two Pointers + In-place Array Manipulation 🔍 Platform: LeetCode Today’s challenge was to compress a character array in-place by replacing consecutive repeating characters with the character followed by its count. Example: Input: ["a","a","b","b","c","c","c"] Output: ["a","2","b","2","c","3"] Approach: ✔ Use two pointers — one for reading characters and one for writing compressed output ✔ Count consecutive repeating characters ✔ Write the character once and append the count if it is greater than 1 ✔ Modify the array directly without creating extra space Time Complexity: O(n) Space Complexity: O(1) 🔗 Problem Link: https://lnkd.in/eeeWBA4X 🔗 Code: https://lnkd.in/enj4Qcy9 #100DaysOfCode #Day17 #Java #DSA #LeetCode #Strings #TwoPointers #ProblemSolving #CodingJourney

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories