JAVA | O(n) | clean code
\nclass Solution {\n    public String[] divideString(String s, int k, char fill) {\n        ArrayList<String> list = new ArrayList<>();\n        StringBuilder s
```\nclass Solution {\n    public String[] divideString(String s, int k, char fill) {\n        ArrayList<String> list = new ArrayList<>();\n        StringBuilder sb = new StringBuilder();\n        for (char ch : s.toCharArray()) {\n            sb.append(ch);\n            if (sb.length() == k) {\n                list.add(sb.toString());\n                sb.setLength(0);\n            }\n        }\n        if (sb.length() > 0) {\n           int count = k - sb.length();\n            for (int i = 0; i < count; i++) {\n                sb.append(fill);\n            }\n            list.add(sb.toString());\n        }\n        return list.toArray(new String[list.size()]);\n    }\n}\n```\n\nA little bit of refinement\n\n```\nclass Solution {\n    public String[] divideString(String s, int k, char fill) {\n        int chunks = s.length() % k != 0? (s.length() / k) + 1 : s.length() / k;\n        String[] res = new String[chunks];\n        StringBuilder sb = new StringBuilder(s);\n        if (s.length() % k > 0) {\n            for (int i = 0; i < k - (s.length() % k); i++) {\n                sb.append(fill);\n            }\n        }\n        s = sb.toString();\n        sb.setLength(0);\n        int i = 0;\n        for (char ch : s.toCharArray()) {\n            sb.append(ch);\n            if (sb.length() == k) {\n                res[i++] = sb.toString();\n                sb.setLength(0);\n            }\n        }\n        return res;\n    }\n}\n```
[]