shlogg · Early preview
Md Ariful Haque @mah-shamim

Adding Spaces To A String With Two Pointers

Add spaces before characters at given indices in string s using two pointers and efficient appending.

2109. Adding Spaces to a String
Difficulty: Medium
Topics: Array, Two Pointers, String, Simulation
You are given a 0-indexed string s and a 0-indexed integer array spaces that describes the indices in the original string where spaces will be added. Each space should be inserted before the character at the given index.

For example, given s = "EnjoyYourCoffee" and spaces = [5, 9], we place spaces before 'Y' and 'C', which are at indices 5 and 9 respectively. Thus, we obtain "Enjoy Your Coffee".

Return the modified string after the spaces have been added.
Example 1:

Input: s = "LeetcodeHelpsMe...