Problem Β· String
Prepare Notification π¬
Learn this problemProblem statement
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.
Function
prepareNotification(message: String, K: int) β StringExamples
Example 1
message = "And now here is my secret"K = 15return = "And now ..."no explanation is provided π₯Ή
Example 2
message = "There is an animal with four legs"K = 15return = "There is an ..."no explanation is provided
Example 3
message = "super dog"K = 4return = "..."no explanation is provided
Example 4
message = "how are you"K = 20return = "how are you"no explanation is provided
Constraints
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)