Submitted by: Mohammad Sajid Anwar
You are given a string text of words that are placed among number of spaces.
Write a script to rearrange the spaces so that there is an equal number of spaces between every pair of adjacent words and that number is maximised. If you can't distribute, place the extra speaces at the end. Finally return the string.
Input: $str = " challenge "
Output: "challenge "
We have 4 spaces and 1 word. So all spaces go to the end.
Input: $str = "coding is fun"
Output: "coding is fun"
We have 4 spaces and 3 words (2 gaps). So 2 spaces per gap.
Input: $str = "a b c d"
Output: "a b c d "
We have 4 spaces and 4 words (3 gaps). So 1 space per gap and 1 remainder.
Input: $str = " team pwc "
Output: "team pwc"
We have 10 spaces and 2 words (1 gap). So 10 spaces per gap.
Input: $str = " the weekly challenge "
Output: "the weekly challenge "
We have 9 spaces and 3 words (2 gaps). So 4 spaces per gap and 1 remainder.
Submitted by: Mohammad Sajid Anwar
You are given a string.
Write a script to return the length of the largest substring between two equal characters excluding the two characters. Return -1 if there is no such substring.
Input: $str = "aaaaa"
Output: 3
For character "a", we have substring "aaa".
Input: $str = "abcdeba"
Output: 5
For character "a", we have substring "bcdeb".
Input: $str = "abbc
Output: 0
For character "b", we have substring "".
Input: $str = "abcaacbc"
Output: 4
For character "a", we have substring "bca".
For character "b", we have substring "caac".
For character "c", we have substring "aacb".
Input: $str = "laptop"
Output: 2
For character "p", we have substring "to".
Last date to submit the solution 23:59 (UK Time) Sunday 10th May 2026.