C++ Solution with explanation
\n// First I thought of binary search , but realised soon , I can iterate over all the b\'s.\n// Let\'s say answer is of size x , We know x-1 words will have le
```\n// First I thought of binary search , but realised soon , I can iterate over all the b\'s.\n// Let\'s say answer is of size x , We know x-1 words will have length limit & last word should be <=limit\n// Validate the last word , picking b greedily  :)\nclass Solution {\npublic:\n    vector<string> splitMessage(string message, int limit) {\n        int b = 0 , cnt = 0 , sm = 0;\n        vector<string> ans;\n        for(int i=1; i<=10000; i++) {\n            sm+=Size(i);  // sum of length of (\'1\') + (\'2\')... (\'i\')  , we are calculating sum of length of all a\'s.\n            int cnt = ((3 + Size(i)) * i) + message.size() + sm;   // sum of (3 is "</>"  + i\'s size ) * i times , message , sm \n            int len = (i-1) * limit; // till second last\n            if(cnt - len <= limit) {  // if last is bigger than limit , its invalid!\n                b = i;\n                break;\n            }\n        }\n        string s = "";\n        cnt = 1;\n        for(int i=0; i<message.size(); i++) {\n              if(limit - (3 + Size(cnt) + Size(b) + (int)s.size())>0) {\n                   s+=message[i];\n              }else {\n                   string word = s + "<" + to_string(cnt) + "/" + to_string(b) + ">";\n                   ans.push_back(word);\n                   s = message[i];\n                   cnt++;\n              }\n        }\n         string word = s + "<" + to_string(cnt) + "/" + to_string(b) + ">";\n         ans.push_back(word);\n         if(cnt>b || word.size()>limit) return {};   // cnt is last value of a , which should never be > than b , also last word size should be <= limit!\n        return ans;\n    }\n    int Size(int n) {\n         return to_string(n).size();\n    }\n};\n```
['Math', 'C']