Tap here to switch tabs
Problem
Submissions

Problem: Rearrange Spaces Between Words

med
30 min
Try to solve the Rearrange Spaces Between Words problem.

Statement

You are given a string text consisting of words separated by spaces.

Rearrange the spaces such that they are distributed equally between every pair of adjacent words, maximizing the number of spaces between them. Any remaining spaces that cannot be evenly distributed must be appended to the end of the string.

Return the resulting string after rearranging the spaces.

Note: If text contains only 11 word, no spaces can be placed between words, so all spaces must be appended to the end of the string.

Constraints:

  • 1≤1 \leq text.length ≤100\leq 100

  • text consists of lowercase English letters and ' '.

  • text contains at least 11 word.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Rearrange Spaces Between Words

med
30 min
Try to solve the Rearrange Spaces Between Words problem.

Statement

You are given a string text consisting of words separated by spaces.

Rearrange the spaces such that they are distributed equally between every pair of adjacent words, maximizing the number of spaces between them. Any remaining spaces that cannot be evenly distributed must be appended to the end of the string.

Return the resulting string after rearranging the spaces.

Note: If text contains only 11 word, no spaces can be placed between words, so all spaces must be appended to the end of the string.

Constraints:

  • 1≤1 \leq text.length ≤100\leq 100

  • text consists of lowercase English letters and ' '.

  • text contains at least 11 word.