Round 1
Questions: Given a string containing a sequence of words separated by whitespace-like characters, add underscores so that the words can be printed neatly given a character limit per line. Assume that there are no words that exceed the line's width.
Your solution will take as input:
- A string of words separated by whitespace-like characters
- An integer representing the length which each line in the output must be
If there is any amount or type of whitespace between two words in the input string, they are considered separate words with the exception of hyphenated words.
Consider the following sample input:
"a cat is an animal" 6
The function should output the following:
['a__cat', 'is__an', 'animal']
Even Underscore Distribution: Given the following input:
"cat is an animal and so is a dog" 12
Your function should return:
['cat__is__an_', 'animal___and', 'so_is_a_dog_']
Single Word Lines: For example, the input:
"human!" 8
Will output:
["_human__"]
Hyphenated Words: For example, given the following input:
"auto-complete is my go - to" 8
Your function should return:
['_auto-__', 'complete', 'is____my', '_go-to__']
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.