File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,771 LeetCode solutions in JavaScript
1
+ # 1,772 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1638
1638
2134|[ Minimum Swaps to Group All 1's Together II] ( ./solutions/2134-minimum-swaps-to-group-all-1s-together-ii.js ) |Medium|
1639
1639
2135|[ Count Words Obtained After Adding a Letter] ( ./solutions/2135-count-words-obtained-after-adding-a-letter.js ) |Medium|
1640
1640
2136|[ Earliest Possible Day of Full Bloom] ( ./solutions/2136-earliest-possible-day-of-full-bloom.js ) |Hard|
1641
+ 2138|[ Divide a String Into Groups of Size k] ( ./solutions/2138-divide-a-string-into-groups-of-size-k.js ) |Easy|
1641
1642
2140|[ Solving Questions With Brainpower] ( ./solutions/2140-solving-questions-with-brainpower.js ) |Medium|
1642
1643
2145|[ Count the Hidden Sequences] ( ./solutions/2145-count-the-hidden-sequences.js ) |Medium|
1643
1644
2154|[ Keep Multiplying Found Values by Two] ( ./solutions/2154-keep-multiplying-found-values-by-two.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2138. Divide a String Into Groups of Size k
3
+ * https://leetcode.com/problems/divide-a-string-into-groups-of-size-k/
4
+ * Difficulty: Easy
5
+ *
6
+ * A string s can be partitioned into groups of size k using the following procedure:
7
+ * - The first group consists of the first k characters of the string, the second group consists
8
+ * of the next k characters of the string, and so on. Each element can be a part of exactly one
9
+ * group.
10
+ * - For the last group, if the string does not have k characters remaining, a character fill is
11
+ * used to complete the group.
12
+ *
13
+ * Note that the partition is done so that after removing the fill character from the last group
14
+ * (if it exists) and concatenating all the groups in order, the resultant string should be s.
15
+ *
16
+ * Given the string s, the size of each group k and the character fill, return a string array
17
+ * denoting the composition of every group s has been divided into, using the above procedure.
18
+ */
19
+
20
+ /**
21
+ * @param {string } s
22
+ * @param {number } k
23
+ * @param {character } fill
24
+ * @return {string[] }
25
+ */
26
+ var divideString = function ( s , k , fill ) {
27
+ const paddedString = s + fill . repeat ( ( k - s . length % k ) % k ) ;
28
+ const result = [ ] ;
29
+
30
+ for ( let i = 0 ; i < paddedString . length ; i += k ) {
31
+ result . push ( paddedString . slice ( i , i + k ) ) ;
32
+ }
33
+
34
+ return result ;
35
+ } ;
You can’t perform that action at this time.
0 commit comments