Say you are given two sentences with a line in the middle (denoted by '|'):
a cat ran across the |I like to sing and
street |dance the night
|awayThe only thing you have control over is moving the middle line, while the total length of each line is fixed. Design an algorithm to figure out how where to place the middle line such that you ensure that the two sentences take up the least amount of lines.
For example, the answer would be making the line such that it's like this:
a cat ran across the |I like to sing and dance
street | the night awayShifting the line all the way to the left would result in:
a |I like to sing and dance the night away
cat|
ran|
...|
...|Basically, in this example, the most you can shift to the left is dependent on the length of the longest word in the "left" sentence.
Interviewer was looking for an answer better than O(N^2) runtime (I'm guessing O(N)) with some sort of DP solution. Couldn't crack it.