Reversing a String in-place with Two Pointers

🚀 Day 57 of #100DaysOfCode Today’s problem was a clean and classic two-pointer exercise — 🔁 LeetCode 344: Reverse String Simple on the surface, but a great reminder of in-place algorithms and pointer manipulation. 📌 Problem Summary You’re given a character array s. Your task is to reverse the array in-place, using O(1) extra space. 🧠 Approach Used: Two Pointers ✔️ Initialize: left = 0 right = s.length - 1 ✔️ Swap characters while left < right, then move pointers inward. This ensures: No extra memory Linear traversal Clean and readable logic ⚙️ Complexity Analysis ⏱ Time Complexity: O(n) 💾 Space Complexity: O(1) (in-place) ✔️ 477 / 477 test cases passed 🚀 Runtime: 0 ms (Beats 100%) 🔥 Key Learning Even the simplest problems reinforce core fundamentals: Two-pointer technique In-place operations Space optimization Mastering basics = dominating harder problems later 💪 Onward to Day 58 🚀 #100DaysOfCode #LeetCode #ReverseString #TwoPointers #Java #DSA #ProblemSolving #CodingJourney #Consistency

  • graphical user interface

To view or add a comment, sign in

Explore content categories