Problem Brief
Prepare Notification π¬
FULLTIMEOA
Prepare a notification of the given message which will be displayed on a mobile device. The message is made of words separated by single spaces. The length of the notification is limited to K characters. If the message is too long to be displayed fully, some words from the end of the message should be cropped, keeping in mind that:
If all the words need to be cropped, the notification is '...' (three dots without a space).
Write up the func in the editor π
Given a string message and an integer K, returns the notification to display, which has no more than K chars, as described above.
1Example 1
Input
message = "And now here is my secret", K = 15
Output
"And now ..."
Explanation
no explanation is provided π₯Ή
2Example 2
Input
message = "There is an animal with four legs", K = 15
Output
"There is an ..."
Explanation
no explanation is provided
3Example 3
Input
message = "super dog", K = 4
Output
"..."
Explanation
no explanation is provided
4Example 4
Input
message = "how are you", K = 20
Output
"how are you"
Explanation
no explanation is provided
Constraints
Limits and guarantees your solution can rely on.
K is an integer within the range [3, 500]the len of string msg i within the range [1, 500]string msg is made of English letters ('a' - 'z', 'A-Z') and space ('')msg does not contains spaces at the beginning of at the endwords are separated by a single space (there are never 2 or more consecutive sapces)