Kotlin Solution with Math
Approach\nWe can solve this problem doing pure math calculations.\n\n1. We first try to split it with at most 9 copies. We know the suffix will be of the form "
# Approach\nWe can solve this problem doing pure math calculations.\n\n1. We first try to split it with at most 9 copies. We know the suffix will be of the form "<1/9>", which will always have 5 chars. This means that we have only (limit -5) chars that we can extract from the original string. Therefore we would need (Message Length / (Limit-5)) Copies. If number of copies is greater than 9 then we know we need to check now with at most 99\n2. Now we try to split it with at most 9 copies. We know we will have 9 copies of the following form "<1/99>" whose length is (Limit -6) and then we will have 90 copies of the form "<10/99>" whose length is (Limit-7). To get how many copies we will need we can do quick math.\n\nFor other cases we have similar logic\n\n# Code\n\nCode can be simplify but tried to keep it self explained.\n```\nimport kotlin.math.ceil\nimport kotlin.math.min\nclass Solution {\n\n    fun splitAtMost9(length: Int, limit: Int):Int{\n        if(limit <= 5)  return -1\n        val numberOfCopies = ceil(length/(limit - 5).toFloat()).toInt()\n        return if(numberOfCopies <= 9)numberOfCopies else -1\n    }\n\n    fun splitWithAtMost99(length: Int, limit: Int):Int{\n        if(limit <= 7)  return -1\n        val restOfStringLength = length - (limit-6)*9\n        val numberOfCopies = ceil(restOfStringLength/(limit-7).toFloat()).toInt() + 9\n        return if(numberOfCopies <= 99) numberOfCopies else -1\n    }\n\n    fun splitWithAtMost999(length: Int, limit: Int):Int{\n        if(limit <= 9)  return -1\n        var restOfStringLength = length - (limit-7)*9\n        restOfStringLength = restOfStringLength - (limit-8)*90\n\n        val numberOfCopies = ceil(restOfStringLength/(limit-9).toFloat()).toInt() + 99\n        return if(numberOfCopies <= 999) numberOfCopies else -1\n    }\n\n    fun splitWithAtMost9999(length: Int, limit: Int):Int{\n        if(limit <= 9)  return -1\n        var restOfStringLength = length - (limit-8)*9\n        restOfStringLength = restOfStringLength - (limit-9)*90\n        restOfStringLength = restOfStringLength - (limit-10)*900\n\n        val numberOfCopies = ceil(restOfStringLength/(limit-11).toFloat()).toInt() + 999\n        return if(numberOfCopies <= 9999) numberOfCopies else -1\n    }\n\n    fun splitMessage(message: String, limit: Int): Array<String> {\n        var copies = splitAtMost9(message.length,limit)\n        if(copies == -1){\n            copies = splitWithAtMost99(message.length,limit)\n        }\n        if(copies == -1){\n            copies = splitWithAtMost999(message.length,limit)\n        }\n        if(copies == -1){\n            copies = splitWithAtMost9999(message.length,limit)\n        }\n        if(copies <= 0 ){\n            return emptyArray<String>()\n        }\n        val ans = Array<String>(copies){""}\n        var appended = 0\n        for(i in 1..copies){\n            val toAppendLength = limit - "<$i/$copies>".length\n            ans[i-1] = message.substring(appended,min(appended+toAppendLength,message.length)) + "<$i/$copies>"\n            appended = appended+toAppendLength\n        }\n\n        return ans\n        \n    }\n}\n```
['Kotlin']