Solution Beats 100% Binary Search
Intuition\n Describe your first thoughts on how to solve this problem. \nBeats 100%\n\n# Approach\n Describe your approach to solving the problem. \nBinary sear
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nBeats 100%\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nBinary search\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(logn)\n![Screenshot 2024-06-25 at 12.45.14\u202FAM.png](https://assets.leetcode.com/users/images/2480ad1a-19d7-4ffd-b997-cc113c2b6c64_1719290802.6219628.png)\n\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n\n# Code\n```\nclass Solution(object):\n    def splitMessage(self, message, limit):\n        """\n        :type message: str\n        :type limit: int\n        :rtype: List[str]\n        """\n        if limit < 5:\n            return []\n\n        def message_length(num):\n            min_length = 4 + len(num)\n            operand = 1\n            size = 0\n            for i in range(len(num) - 1):\n                size += (limit - min_length) * 9 * operand\n                min_length += 1\n                operand *= 10\n            calculated = \'9\' * (len(num) - 1) if (len(num) - 1) > 0 else 0\n            rest = int(num) - int(calculated)\n            max_suffix_len = len(num) * 2 + 3\n            size += (limit - max_suffix_len) * rest\n            return size\n\n        max_part = \'9\'\n        while message_length(max_part) < len(message):\n            max_part += \'9\'\n            if limit < len(max_part) * 2 + 3:\n                return []\n        \n        last_suffix_len = len(max_part) * 2 + 3\n        shortest_last_part = last_suffix_len + 1\n        bias = limit - shortest_last_part\n        hi = int(max_part)\n        lo = pow(10, len(max_part) - 1)\n        mid = (lo + hi) // 2\n        while len(message) < message_length(str(mid)) - bias or \\\n              len(message) > message_length(str(mid)):\n            if message_length(str(mid)) > len(message):\n                hi = mid - 1\n            else:\n                lo = mid + 1\n            mid = (lo + hi) // 2\n        \n        pointer = 0\n        result = []\n\n        for i in range(mid):\n            msg_len = limit - 3 - len(str(i+1)) - len(str(mid))\n            s = message[pointer:pointer+msg_len]\n            s = s + \'<\' + str(i+1) + \'/\' + str(mid) + \'>\'\n            result.append(s)\n            pointer += msg_len\n\n        return result\n```
['Python']