Practice Chunk Array
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Easy#2677
LeetCode ProblemChunk Array
Problem Statement
Given an array arr and a chunk size size, return a chunked array. A chunked array contains the original elements in arr, but consists of subarrays each of length size. The length of the last subarray may be less than size if arr.length is not evenly divisible by size. Please solve it without using lodash's _.chunk function.
Source: Chunk Array on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
arr = [1,2,3,4,5], size = 1
Output
[[1],[2],[3],[4],[5]]
# Example 2
Input
arr = [1,9,6,3,2], size = 3
Output
[[1,9,6],[3,2]]
# Example 3
Input
arr = [8,5,3,2,6], size = 6
Output
[[8,5,3,2,6]]
# Example 4
Input
arr = [], size = 1
Output
[]
Constraints
arr is a string representing the array.
2 <= arr.length <= 10^5
1 <= size <= arr.length + 1
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.