👏Beats 96.31% of users with Java || Simple & Easy Two Pointer, Substring Approach 💥🔥
Intuition\nAdd fill into the string untill string is not complete divided by k and add k size of substrings into the string array of ans.\n\n# I Think This Can 
# Intuition\nAdd fill into the string untill string is not complete divided by k and add k size of substrings into the string array of ans.\n\n# I Think This Can Help You\n![Screenshot 2024-03-01 105912.png](https://assets.leetcode.com/users/images/cea850c9-4e3f-458d-80b4-be114d9076ee_1709740682.8526082.png)\n\n\n# Approach\n1. Check if string\'s length is equal to k just convert whole string into the character array and return it.\n2. Create string builder sb and copy the string s into the string builder sb.\n3. Iterate and add fill into the sb untill sb.length is complete divided by k.\n4. Make array of string ans size of sb.length divided by k.\n5. Make two pointers i as a 0 & j as a k-1.\n6. Create count variable to count no. of index to add string into the ans array.\n7. Iterate the loop until sb.length is greater than j.\n8. Store the substring i to j+1 into the string of cnt.\n9. Increase i & j by k and cnt by 1.\n10. return ans.\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\n    public String[] divideString(String s, int k, char fill) {\n        if(s.length() == k){   // Check if string\'s length is equal to k just convert whole string into the character array and return it.\n            return new String[] {s};\n        }\n        StringBuilder sb = new StringBuilder(s);   // Create string builder sb and copy the string s into the string builder sb.\n        while(sb.length()%k!=0){   // Iterate and add fill into the sb untill sb.length is complete divided by k.\n            sb.append(fill);\n        }\n        String[] ans = new String[sb.length()/k];   // Make array of string ans size of sb.length divided by k.\n        int i=0;   //  Make two pointers i as a 0 & j as a k-1.\n        int j= k-1;\n        int cnt=0;   // Create count variable to count no. of index to add string into the ans array.\n        while(j<sb.length()){   // Iterate the loop until sb.length is greater than j.\n            ans[cnt] = sb.substring(i,j+1);   // Store the substring i to j+1 into the string of cnt.\n            i+=k;   // Increase i & j by k and cnt by 1.\n            j+=k;\n            cnt++;\n        }\n        return ans;   // return ans.\n    }\n}\n```\n\n![_85ee799f-fdcb-4c1e-8f96-21990237271b.jpeg](https://assets.leetcode.com/users/images/08be69be-f5cf-4254-abf5-5209cf161819_1709741593.2894087.jpeg)\n
['Two Pointers', 'String', 'Simulation', 'Java']