Twitter Phone Screen Question
Anonymous User
3803

Similar to https://leetcode.com/problems/text-justification/

Implement a method split(example_text, limit); , where it takes 2 params - example_text and a limit, split the text into a list of strings which can contain atmost(nearest to the limit) limited characters per string.

There are 2 tweaks to the text justification problem

  1. Append which part of the message user is viewing , ex., (1/5) , (2/5) , etc.,
  2. Dont break a word, if your limit breaks a word move it to the next string

NOTE: The suffix(1/5) also counts into the limit and you dont know the total count of Strings until you reach the end.

/*String example_text = "Write a function that splits long SMS string"
      + " into smaller pieces. Each piece should be less than or "
      + "equal to 160 characters and contains indices at the end." 
      + " Function should not break words into pieces. If word does"
      + " not fit -- it should go to the next SMS."; => 600 / 60 => 10

List<String> lines = split(example_text, 60);

*/

/* Output:
Write a function that splits long SMS string into (1/5) 55
smaller pieces. Each piece should be less than or (2/5) 55
equal to 160 characters and contains indices at the (3/5) 57
end. Function should not break words into pieces. If (4/5) 58
word does not fit -- it should go to the next SMS. (5/5) 56
*/
Comments (8)