Python, Go | Simple solution with explanation | O(N)
Intuition\n Describe your first thoughts on how to solve this problem. \nLet\'s consider a scenario where we merge the split string back without excluding the s
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nLet\'s consider a scenario where we merge the split string back without excluding the suffixes. Knowing the **original size** of the string and the **number** of its parts, we can calculate the overall size of this combined string.\n\nExample: `"short mess<1/2>age<2/2>"`\n\u2022 Original length: 13\n\u2022 Number of parts: 2\n\u2022 Length of each suffix: 5\n\u2022 Total length: 13 + 2 * 5 = 23\n\nNote that `limit * parts >= total_length`. Knowing the original size of the string, limit and total size of the suffixes, it is possible to find out the number of parts\n\u2022 Limit: 15\n\u2022 `15 * parts >= 13 + parts * 5; parts >= 13 / (15 - 5); parts >= 1.3`\n\u2022 Fractions cannot represent parts, so `parts = ceil(1.3) = 2`\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nLet\'s apply it to all possible ranges of the parts (1-10000)\n**\u2022 1 <= parts < 10**\ntotal_length = msg_length + parts * 5\nlimit * parts >= msg_length + parts * 5\nparts >= msg_length / (limit - 5)\n\n**\u2022 10 <= parts < 100**\ntotal_length = msg_length + 9 * 6 + (parts - 9) * 7\n*Explanation*: 9 parts with "<K/NN>" suffixes AND (total_parts - 9) parts with "<KK/NN>" suffixes.\nlimit * parts >= msg_length - 9 + parts * 7\nparts >= (msg_length - 9) / (limit - 7)\n\n**\u2022 100 <= parts < 1000**\ntotal_length = msg_length + 9 * 7 + 90 * 8 + (parts -  99) * 9\nlimit * parts >= msg_length - 108 + parts * 9\nparts >= (msg_length - 108) / (limit - 9)\n\n**\u2022 1000 <= parts < 10000**\ntotal_length = msg_length + 9 * 8 + 90 * 9 + 900 * 10 + (parts - 999) * 11\nlimit * parts >= msg_length - 1107 + parts * 11\nparts >= (msg_length - 1107) / (limit - 11)\n\n**\u2022 parts = 10000**\ntotal_length = msg_length + 9 * 9 + 90 * 10 + 900 * 11 + 9000 * 12 + 13\nlimit * parts >= msg_length + 118894\nparts >= (msg_length + 118894) / limit\n\nDetermining the exact number of parts to split the string require approximation, as the initial result could potentially fall into the next interval.\n\n# Code\n```python3 []\nimport math\n\n\nclass Solution:\n    def getNumberOfParts(self, message: str, limit: int) -> int:\n        if limit < 6:\n            return 0\n        length = len(message)\n        parts = math.ceil(length / (limit - 5))\n        if 10 <= parts < 100:\n            parts = math.ceil((length - 9) / (limit - 7)) if limit > 7 else 0\n        if 100 <= parts < 1000:\n            parts = math.ceil((length - 108) / (limit - 9)) if limit > 9 else 0\n        if 1000 <= parts < 10000:\n            parts = math.ceil((length - 1107) / (limit - 11)) if limit > 11 else 0\n        if parts > 10000:\n            parts = math.ceil((length + 118894) / limit)\n            if parts > 10000:\n                parts = 0\n        return parts\n\n    def splitMessage(self, message: str, limit: int) -> List[str]:\n        res = []\n        start, end = 0, 0\n        parts = self.getNumberOfParts(message, limit)\n        for i in range(parts):\n            suffix = f"<{i+1}/{parts}>"\n            end = start + limit - len(suffix)\n            res.append(f"{message[start:end]}{suffix}")\n            start = end\n        return res\n```\n```Go []\nimport (\n\t"fmt"\n\t"math"\n)\n\nfunc numberOfParts(message string, limit int) int {\n\tif limit < 6 {\n\t\treturn 0\n\t}\n\tlength := len(message)\n\tparts := int(math.Ceil(float64(length) / float64(limit-5)))\n\tif parts >= 10 && parts < 100 {\n\t\tif limit < 8 {\n\t\t\treturn 0\n\t\t}\n\t\tparts = int(math.Ceil(float64(length-9) / float64(limit-7)))\n\t}\n\tif parts >= 100 && parts < 1000 {\n\t\tif limit < 10 {\n\t\t\treturn 0\n\t\t}\n\t\tparts = int(math.Ceil(float64(length-108) / float64(limit-9)))\n\t}\n\tif parts >= 1000 && parts < 10000 {\n\t\tif limit < 12 {\n\t\t\treturn 0\n\t\t}\n\t\tparts = int(math.Ceil(float64(length-1107) / float64(limit-11)))\n\t}\n    if parts > 10000 {\n        parts = int(math.Ceil(float64(length + 118894) / float64(limit)))\n        if parts > 10000 {\n            parts = 0\n        }\n    }\n\treturn parts\n}\n\nfunc splitMessage(message string, limit int) []string {\n\tvar start int\n\tvar res []string\n\tparts := numberOfParts(message, limit)\n\tfor i := 0; i < parts; i++ {\n\t\tsuffix := fmt.Sprintf("<%d/%d>", i+1, parts)\n\t\tend := min(start+limit-len(suffix), len(message))\n\t\tres = append(res, message[start:end]+suffix)\n\t\tstart = end\n\t}\n\treturn res\n}\n```\n\n# Complexity\n- Time complexity: O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n
['Go', 'Python3']