JAVA soln with explanation
The basic idea for this problem is to determine the appropriate number of parts to divide our input string to, such that each part length is within limit define
The basic idea for this problem is to determine the appropriate number of parts to divide our input string to, such that each part length is within limit defined. One way to determine it is to loop on possible part values and then divide the modified string (containing original string plus all instances of <a/part>) by the part value. This will give us the maximum length of each string part.\n\nAs specified in the question we want the max length of a string part to be lesser or equal to `limit` along with the minimum part value. Thus we loop part in an ascending manner and as soon we get max length of part to be <= `limit`, we break the loop.\n\nFinally after calculating the minimum possible parts, we construct our string array as per requirement.\n```\nclass Solution {\n    public String[] splitMessage(String message, int limit) {\n        int len = message.length(), part;\n        StringBuilder partSb = new StringBuilder();\n        for(part=1;part<=len;part++){\n            int numChars = 0;\n            numChars = part*3; //Accounting for all </> characters in modified string\n            numChars += ((Integer.toString(part)).length())*part; //Accounting for repeated b in modified string\n            partSb.append(Integer.toString(part)); \n            numChars += partSb.length(); //Accounting for a from 1 to b in modified string\n            float remainChars = (float)len+numChars;\n\t\t\t//Finally checking below if the average string length per part is lesser or equal to limit,\n\t\t\t//if yes we get our part value else we continue;\n            if(remainChars/(float)part <= ((float)limit))\n                break;\n        }\n        if(part>len) return new String[]{}; //No suitable part found, return empty string\n        String[] res = new String[part];\n        int idx = 0;\n\t\t//Construct res array as required based on the number of parts determined\n        for(int i=1;i<=part;i++){\n            StringBuilder suffix = new StringBuilder();\n            suffix.append("<").append(Integer.toString(i)).append("/").append(Integer.toString(part)).append(">");\n            StringBuilder prefix = new StringBuilder();\n            if(idx + limit-suffix.length()<=len)\n                prefix.append(message.substring(idx, idx + limit-suffix.length()));\n            else\n                prefix.append(message.substring(idx, len));\n            idx += prefix.length();\n            prefix.append(suffix);\n            res[i-1] = prefix.toString();\n        }\n        return res;\n    }\n}\n//TC : O(n^2) Since we are iterating on all parts and also calculating substring (O(n) operation) in each part,\n//WC complexity would O(n^2) as parts can be almost equal to length of the `message`.\n//SC : O(n) StringBuilder to store part value for each iteration ~ O(n).\n```
['Java']