Coding

Write code to implement a text wrapper that takes in a long string and a character limit as inputs and returns a list of strings, where each string is limited to the specified number of characters, split only at spaces. For example, if the input string is "This is a long sentence that needs to be wrapped", and the character limit is 10, the output should be a list with three strings: ["This is a", "long", "sentence that", "needs to be", "wrapped"].

Data Scientist

Uber

Apple

Snap

Lyft

Amazon Web Services

Whatsapp

Did you come across this question in an interview?

  • Write code to implement a text wrapper that takes in a long string and a character limit as inputs and returns a list of strings, where each string is limited to the specified number of characters, split only at spaces. For example, if the input string is "This is a long sentence that needs to be wrapped", and the character limit is 10, the output should be a list with three strings: ["This is a", "long", "sentence that", "needs to be", "wrapped"].
  • How would you code a text-wrapping function that respects space-delimited words within a character limit?
  • Can you develop a text wrapper function that segments a string based on a character count, without breaking words?
  • How would you write a function that wraps text into lines of a certain length, breaking only at spaces?
  • What would be your approach to implementing a function that wraps text to a specified character length, ensuring it splits at spaces?
  • Could you create a code for a text wrapper that adheres to a given character limit without cutting words in half?
  • How do you plan to code a text wrapping algorithm that breaks lines by space within a character limit?
  • Show how to write a function that neatly wraps text, considering space boundaries and a character threshold.
  • How would you program a text wrapper that divides a string into a list of space-separated strings, each within a character limit?
  • Can you construct a text-wrapping function that breaks a long string into space-separated lines under a character cap?
  • Write code to implement a text wrapper that takes in a long string and a character limit as inputs and returns a list of strings, where each string is limited to the specified number of characters, split only at spaces.

Interview question asked to Data Scientists interviewing at Hootsuite, Zillow, Whatsapp and others: Write code to implement a text wrapper that takes in a long string and a character limit as inputs and returns a list of strings, where each string is limited to the specified number of characters, split only at spaces. For example, if the input string is "This is a long sentence that needs to be wrapped", and the character limit is 10, the output should be a list with three strings: ["This is a", "long", "sentence that", "needs to be", "wrapped"]..