C++ Dividing a Message into Parts with Order-Preserving Suffixes
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem requires splitting a message into multiple segments such that each segment,
### Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires splitting a message into multiple segments such that each segment, including its suffix indicating its order, fits within a specified character limit. The suffix helps in maintaining the order and completeness of the message segments. To solve this, we need to dynamically determine the optimal number of segments and construct each segment accordingly.\n\n### Approach\n<!-- Describe your approach to solving the problem. -->\n1. **Initial Estimation**: Start by estimating the number of segments based on the message length and limit.\n2. **Adjust Segment Count**: Iteratively adjust the number of segments until it stabilizes. This involves:\n   - Calculating the maximum suffix length for the current number of segments.\n   - If the suffix length exceeds the limit, return an empty result.\n   - Recalculating the number of segments based on the total suffix length and message length.\n3. **Create Segments**: Once the number of segments is determined, split the message into these segments. Each segment includes a portion of the message and its corresponding suffix in the format `<current_segment/total_segments>`.\n4. **Return Result**: Collect all segments into a vector and return it.\n\n### Complexity\n- **Time complexity**:\n  The time complexity is $$O(n)$$ because we traverse the message to split it into segments and the while loop iterations are logarithmic concerning the number of segments but overall linear in terms of the message length.\n\n- **Space complexity**:\n  The space complexity is $$O(n)$$ where \\(n\\) is the length of the message, primarily for storing the result segments.\n\n# Code\n```\n\nclass Solution {\npublic:\n    vector<string> splitMessage(string msg, int limit) {\n        int n = msg.size();\n        int segCount = max(1, n / limit);\n        int prevSegCount = 0;\n\n        \n        while (prevSegCount != segCount) {\n            int maxSuffixLen = calcMaxSuffixLen(segCount);\n            if (maxSuffixLen > limit) {\n                return {};  \n            }\n\n            prevSegCount = segCount;\n            segCount = (calcTotalSuffixLen(prevSegCount) + n + limit - 1) / limit;\n        }\n\n        string suffixEnd = "/" + to_string(segCount) + ">";\n        int idx = 0;\n        vector<string> result;\n        result.reserve(segCount);\n\n        \n        for (int i = 1; i <= segCount; ++i) {\n            string suffix = "<" + to_string(i) + suffixEnd;\n            int segLen = limit - suffix.size();\n            string segContent = msg.substr(idx, segLen) + suffix;\n            result.push_back(move(segContent));\n            idx += segLen;\n        }\n\n        return result;\n    }\n\n    int calcMaxSuffixLen(int segCount) {\n        int digits = log10(segCount) + 1;\n        return 2 * digits + 3;\n    }\n\n    \n    int calcTotalSuffixLen(int segCount) {\n        int digits = log10(segCount) + 1;\n        int totalLen = (2 * digits + 3) * segCount;\n\n        for (int i = 1, factor = 10; i < digits; ++i, factor *= 10) {\n            totalLen -= (factor - 1);\n        }\n\n        return totalLen;\n    }\n};\n\n```
['C++']