Do binary search 4 times
Intuition\n Describe your first thoughts on how to solve this problem. \nAt first, I thought I only need to do one binary search, but then I realized that for d
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAt first, I thought I only need to do one binary search, but then I realized that for different post length( the length of "/#number of parts>") it is not monotonic. There are at most 4 post length, since the max length is 10^4, so we do binary search for times.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    int limit;\n    String message;\n    public String[] splitMessage(String message, int limit) {\n        this.limit = limit;\n        this.message = message;\n        int max = 10;\n        int min = 1;\n        \n        for(int i = 1; i<=4; i++) {\n            max = Math.min(message.length(), max);\n            int m = max;\n            int mi = min;\n            if(max!=message.length()) max = max-1;\n            if(min>message.length()) break;\n            if(i == 2) System.out.println(max);\n            while(min+1<max) {\n                int mid = (max+min)/2;\n                int val = helper(mid);\n            \n                if(val == Integer.MAX_VALUE) max = mid - 1;\n                else if(val == Integer.MIN_VALUE) min = mid+1;\n                else if(val == message.length()) min = mid;\n                else min = mid;\n            }\n            \n            if(helper(min) != message.length()) {\n                if(helper(max) == message.length()){\n                    String[] res = new String[max];\n                    helper2(res);\n                    return res;\n                }\n            } else {\n                String[] res = new String[min];\n                helper2(res);\n                return res;\n            }\n            max = m;\n            min = mi;\n            \n            max*=10;\n            min*=10;\n        }\n        return new String[0];\n\n    }\n    \n    \n\n    public int helper(int count) {\n        String s = Integer.toString(count);\n        int len = s.length()+3;\n        int cur = 1;\n        int res = 0;\n        while(cur*10-1<count) {\n            len+=1;\n            res+=(limit-len) * (cur*10-cur);\n            cur*=10;\n        }\n        \n        if(len>limit)return Integer.MAX_VALUE;\n        \n        cur-=1;\n        //if(count == 11) System.out.println(count);\n        int original = count;\n        \n        count-=cur;\n        \n        res+=(limit-(len+1)) * (count - 1);\n        if(message.length() - res <= 0) return Integer.MAX_VALUE;\n        if(message.length() - res > limit - (len+1)) return Integer.MIN_VALUE;\n        return message.length();\n    }\n\n    public void helper2(String[] res) {\n        String post = "/" + Integer.toString(res.length) + ">";\n        int start = 0;\n        for(int i = 1; i<=res.length-1; i++) {\n            String postString = "<" + Integer.toString(i) + post;\n            int len = limit - postString.length();\n            String sub = message.substring(start, start+len) + postString;\n            //System.out.println(sub);\n            res[i-1] = sub;\n            start+=len;\n        }\n        String postString = "<" + Integer.toString(res.length) + post;\n        res[res.length-1] = message.substring(start, message.length()) + postString;\n    }\n}\n```
['Java']