FastPrepSplit Text into Minimum Suffixed SMS Messages

Split Text into Minimum Suffixed SMS Messages

ZipRecruiter logoZipRecruiter● HardNEW GRADOA
Learn

Problem statement

Split every text character in order into the minimum number y of messages. Message x ends with suffix <x/y>, which counts toward limit.

Every nonlast message must have total length exactly limit; the last may be shorter. Each message contains at least one text character. Return the first feasible split, or an empty array.

Function

splitSms(text: String, limit: int) → String[]

Examples

Example 1

text = "abcdefghij"limit = 7return = ["ab<1/5>","cd<2/5>","ef<3/5>","gh<4/5>","ij<5/5>"]

Five messages are the first total count with enough capacity.

Example 2

text = "abc"limit = 10return = ["abc<1/1>"]

One message fits.

Constraints

  • 1 <= text.length <= 10000
  • 1 <= limit <= 10000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String[] splitSms(String text, int limit) {
    // Write your code here.
}
text"abcdefghij"
limit7
expected["ab<1/5>", "cd<2/5>", "ef<3/5>", "gh<4/5>", "ij<5/5>"]
Checking account…