1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode/originData/chunk-array.json

56 lines
5.6 KiB
JSON
Raw Normal View History

2023-05-15 17:43:00 +08:00
{
"data": {
"question": {
"questionId": "2798",
"questionFrontendId": "2677",
"boundTopicId": null,
"title": "Chunk Array",
"titleSlug": "chunk-array",
"content": "<p>Given an array <code>arr</code> and&nbsp;a chunk size&nbsp;<code>size</code>, return a&nbsp;<strong>chunked</strong> array. A&nbsp;<strong>chunked</strong>&nbsp;array contains the original elements in&nbsp;<code>arr</code>, but&nbsp;consists of subarrays each of length&nbsp;<code>size</code>. The length of the last subarray may be less than&nbsp;<code>size</code>&nbsp;if <code>arr.length</code>&nbsp;is not evenly divisible by <code>size</code>.</p>\n\n<p>You may assume the&nbsp;array&nbsp;is&nbsp;the output of&nbsp;<code>JSON.parse</code>. In other words, it is valid JSON.</p>\n\n<p>Please solve it without using lodash&#39;s&nbsp;<code>_.chunk</code>&nbsp;function.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,2,3,4,5], size = 1\n<strong>Output:</strong> [[1],[2],[3],[4],[5]]\n<strong>Explanation:</strong> The arr has been split into subarrays each with 1 element.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [1,9,6,3,2], size = 3\n<strong>Output:</strong> [[1,9,6],[3,2]]\n<strong>Explanation:</strong> The arr has been split into subarrays with 3 elements. However, only two elements are left for the 2nd subarray.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [8,5,3,2,6], size = 6\n<strong>Output:</strong> [[8,5,3,2,6]]\n<strong>Explanation:</strong> Size is greater than arr.length thus all elements are in the first subarray.\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> arr = [], size = 1\n<strong>Output:</strong> []\n<strong>Explanation:</strong> There are no elements to be chunked so an empty array is returned.</pre>\n\n<p>&nbsp;</p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>arr is a valid JSON array</code></li>\n\t<li><code>2 &lt;= JSON.stringify(arr).length &lt;= 10<sup>5</sup></code></li>\n\t<li><code>1 &lt;= size &lt;= arr.length + 1</code></li>\n</ul>\n",
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 35,
"dislikes": 1,
"isLiked": null,
"similarQuestions": "[]",
"exampleTestcases": "[1,2,3,4,5]\n1\n[1,9,6,3,2]\n3\n[8,5,3,2,6]\n6\n[]\n1",
"categoryTitle": "JavaScript",
"contributors": [],
"topicTags": [],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "JavaScript",
"langSlug": "javascript",
"code": "/**\n * @param {Array} arr\n * @param {number} size\n * @return {Array[]}\n */\nvar chunk = function(arr, size) {\n \n};\n",
"__typename": "CodeSnippetNode"
},
{
"lang": "TypeScript",
"langSlug": "typescript",
"code": "function chunk(arr: any[], size: number): any[][] {\n\n};\n",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"1.1K\", \"totalSubmission\": \"1.3K\", \"totalAcceptedRaw\": 1096, \"totalSubmissionRaw\": 1329, \"acRate\": \"82.5%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "[1,2,3,4,5]\n1",
"metaData": "{\n \"name\": \"chunkify\",\n \"params\": [\n {\n \"name\": \"arr\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"size\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [],
"enableRunCode": true,
"enableTestMode": false,
"enableDebugger": false,
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
"libraryUrl": null,
"adminUrl": null,
"challengeQuestion": null,
"__typename": "QuestionNode"
}
}
}