Tap here to switch tabs
Problem
Submissions

Problem: Adding Spaces to a String

med
30 min
Try to solve the Adding Spaces to a String problem.

Statement

You are given a 00 indexed string s and a 00 indexed integer array spaces that contains the indices in the original string where spaces should be added.

Each space should be inserted immediately before the character located at the corresponding index in s.

Return the modified string after inserting all the spaces.

Constraints:

  • 1≤1 \leq s.length ≤3×105\leq 3 \times 10^5

  • s consists only of lowercase and uppercase English letters.

  • 1≤1 \leq spaces.length ≤3×105\leq 3 \times 10^5

  • 0≤0 \leq spaces[i] ≤\leq s.length −1- 1

  • All the values of spaces are strictly increasing.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Adding Spaces to a String

med
30 min
Try to solve the Adding Spaces to a String problem.

Statement

You are given a 00 indexed string s and a 00 indexed integer array spaces that contains the indices in the original string where spaces should be added.

Each space should be inserted immediately before the character located at the corresponding index in s.

Return the modified string after inserting all the spaces.

Constraints:

  • 1≤1 \leq s.length ≤3×105\leq 3 \times 10^5

  • s consists only of lowercase and uppercase English letters.

  • 1≤1 \leq spaces.length ≤3×105\leq 3 \times 10^5

  • 0≤0 \leq spaces[i] ≤\leq s.length −1- 1

  • All the values of spaces are strictly increasing.