Divide a String Into Groups of Size k LeetCode solution in C++
1class Solution {2public:3vector<string> divideString(string s, int k, char fill) {4vector<string> v;5for (int i = 0; i < s.size(); i = i + k) {6string t = s.substr(i, k); // make substring of size atmost k78if (t.size() == k) // if size if k then push9{10v.push_back(t);11continue;12}1314int l = t.size(); // if it is the last group and size if less than k15for (int j = 0; j < (k - l); j++) // add fill char to t to make size k16t += fill;1718v.push_back(t);19}20return v;21}22};