


Let the given sentence be: [ “what”, “must”, “be”, “shall”, “be.”]
And L=12.
The justified output will be :
[ “what must be”
“Shall be.” ]
Note that the last line is only left justified.
The first line of input contains an integer ‘T’ representing the number of test cases. Then the test cases follow.
The first line of each test case contains a single integer ‘n’ denoting the number of words in the sentence.
The second line of each test case contains space separated strings denoting the word in the sentence. Note that no word has space in between it.
The third line of each test case contains the integer ‘L’ denoting the number of characters in each line in the justified output
For each test case, return an array of strings denoting the justified output of the given sentence.
The output for each test case is in a separate line.
1. You do not need to print anything; it has already been taken care of.
2. The words do not contain whitespaces.
3. It is guaranteed that L is always greater than the number of characters in any of the given words in the given array ‘words’
1. Find all words whose combined width( accounting for the gap of one for each word) is less than L.
2. Find the total padding which can be added to each word to make the whole container width equal to L.
3. Find the extra padding and append it uniformly to the first few words.
4. Append the spaces to every word in the list except the last.
5. Return final result.
Using the above algorithm we can have the following approach: