Solved LeetCode 1528: Shuffle String in Java

💡 LeetCode 1528 – Shuffle String 💡 Today, I solved LeetCode Problem #1528: Shuffle String, which tests how well you can handle index mapping and string reconstruction in Java — an elegant exercise in array manipulation and string handling. ✨ 🧩 Problem Overview: You’re given a string s and an integer array indices. Each character at position i in s must be moved to position indices[i] in the new string. Return the final shuffled string. 👉 Example: Input → s = "codeleet", indices = [4,5,6,7,0,2,1,3] Output → "leetcode" 💡 Approach: 1️⃣ Create a char array of the same length as s. 2️⃣ Loop through each character in s, placing it at the position specified by indices[i]. 3️⃣ Convert the filled character array back to a string. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n) — Single pass through the string. ✅ Space Complexity: O(n) — For the result character array. ✨ Key Takeaways: Reinforced understanding of index mapping between arrays and strings. Practiced how to reconstruct a string efficiently without using extra data structures. A great example of how simple iteration can solve structured reordering problems cleanly. 🌱 Reflection: Sometimes, challenges like this remind us that not every problem requires a complex algorithm — precision, clarity, and clean mapping logic often do the job best. Staying consistent with such problems builds both confidence and coding discipline. 🚀 #LeetCode #1528 #Java #StringManipulation #ArrayMapping #DSA #ProblemSolving #CleanCode #CodingJourney #AlgorithmicThinking #ConsistencyIsKey

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories