1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode/originData/path-with-minimum-effort.json

201 lines
18 KiB
JSON
Raw Normal View History

2022-03-27 18:27:43 +08:00
{
"data": {
"question": {
"questionId": "1753",
"questionFrontendId": "1631",
"boundTopicId": null,
"title": "Path With Minimum Effort",
"titleSlug": "path-with-minimum-effort",
"content": "<p>You are a hiker preparing for an upcoming hike. You are given <code>heights</code>, a 2D array of size <code>rows x columns</code>, where <code>heights[row][col]</code> represents the height of cell <code>(row, col)</code>. You are situated in the top-left cell, <code>(0, 0)</code>, and you hope to travel to the bottom-right cell, <code>(rows-1, columns-1)</code> (i.e.,&nbsp;<strong>0-indexed</strong>). You can move <strong>up</strong>, <strong>down</strong>, <strong>left</strong>, or <strong>right</strong>, and you wish to find a route that requires the minimum <strong>effort</strong>.</p>\r\n\r\n<p>A route&#39;s <strong>effort</strong> is the <strong>maximum absolute difference</strong><strong> </strong>in heights between two consecutive cells of the route.</p>\r\n\r\n<p>Return <em>the minimum <strong>effort</strong> required to travel from the top-left cell to the bottom-right cell.</em></p>\r\n\r\n<p>&nbsp;</p>\r\n<p><strong>Example 1:</strong></p>\r\n\r\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/04/ex1.png\" style=\"width: 300px; height: 300px;\" /></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> heights = [[1,2,2],[3,8,2],[5,3,5]]\r\n<strong>Output:</strong> 2\r\n<strong>Explanation:</strong> The route of [1,3,5,3,5] has a maximum absolute difference of 2 in consecutive cells.\r\nThis is better than the route of [1,2,2,2,5], where the maximum absolute difference is 3.\r\n</pre>\r\n\r\n<p><strong>Example 2:</strong></p>\r\n\r\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/04/ex2.png\" style=\"width: 300px; height: 300px;\" /></p>\r\n\r\n<pre>\r\n<strong>Input:</strong> heights = [[1,2,3],[3,8,4],[5,3,5]]\r\n<strong>Output:</strong> 1\r\n<strong>Explanation:</strong> The route of [1,2,3,4,5] has a maximum absolute difference of 1 in consecutive cells, which is better than route [1,3,5,3,5].\r\n</pre>\r\n\r\n<p><strong>Example 3:</strong></p>\r\n<img alt=\"\" src=\"https://assets.leetcode.com/uploads/2020/10/04/ex3.png\" style=\"width: 300px; height: 300px;\" />\r\n<pre>\r\n<strong>Input:</strong> heights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]\r\n<strong>Output:</strong> 0\r\n<strong>Explanation:</strong> This route does not require any effort.\r\n</pre>\r\n\r\n<p>&nbsp;</p>\r\n<p><strong>Constraints:</strong></p>\r\n\r\n<ul>\r\n\t<li><code>rows == heights.length</code></li>\r\n\t<li><code>columns == heights[i].length</code></li>\r\n\t<li><code>1 &lt;= rows, columns &lt;= 100</code></li>\r\n\t<li><code>1 &lt;= heights[i][j] &lt;= 10<sup>6</sup></code></li>\r\n</ul>",
"translatedTitle": null,
"translatedContent": null,
"isPaidOnly": false,
"difficulty": "Medium",
2022-05-02 23:44:12 +08:00
"likes": 2099,
"dislikes": 98,
2022-03-27 18:27:43 +08:00
"isLiked": null,
"similarQuestions": "[{\"title\": \"Swim in Rising Water\", \"titleSlug\": \"swim-in-rising-water\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"Path With Maximum Minimum Value\", \"titleSlug\": \"path-with-maximum-minimum-value\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
"exampleTestcases": "[[1,2,2],[3,8,2],[5,3,5]]\n[[1,2,3],[3,8,4],[5,3,5]]\n[[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]",
"categoryTitle": "Algorithms",
"contributors": [],
"topicTags": [
{
"name": "Array",
"slug": "array",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Binary Search",
"slug": "binary-search",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Depth-First Search",
"slug": "depth-first-search",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Breadth-First Search",
"slug": "breadth-first-search",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Union Find",
"slug": "union-find",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Heap (Priority Queue)",
"slug": "heap-priority-queue",
"translatedName": null,
"__typename": "TopicTagNode"
},
{
"name": "Matrix",
"slug": "matrix",
"translatedName": null,
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "C++",
"langSlug": "cpp",
"code": "class Solution {\r\npublic:\r\n int minimumEffortPath(vector<vector<int>>& heights) {\r\n \r\n }\r\n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "Java",
"langSlug": "java",
"code": "class Solution {\r\n public int minimumEffortPath(int[][] heights) {\r\n \r\n }\r\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python",
"langSlug": "python",
"code": "class Solution(object):\r\n def minimumEffortPath(self, heights):\r\n \"\"\"\r\n :type heights: List[List[int]]\r\n :rtype: int\r\n \"\"\"",
"__typename": "CodeSnippetNode"
},
{
"lang": "Python3",
"langSlug": "python3",
"code": "class Solution:\r\n def minimumEffortPath(self, heights: List[List[int]]) -> int:",
"__typename": "CodeSnippetNode"
},
{
"lang": "C",
"langSlug": "c",
"code": "int minimumEffortPath(int** heights, int heightsSize, int* heightsColSize){\r\n\r\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "C#",
"langSlug": "csharp",
"code": "public class Solution {\r\n public int MinimumEffortPath(int[][] heights) {\r\n \r\n }\r\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "JavaScript",
"langSlug": "javascript",
"code": "/**\r\n * @param {number[][]} heights\r\n * @return {number}\r\n */\r\nvar minimumEffortPath = function(heights) {\r\n \r\n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "Ruby",
"langSlug": "ruby",
"code": "# @param {Integer[][]} heights\r\n# @return {Integer}\r\ndef minimum_effort_path(heights)\r\n \r\nend",
"__typename": "CodeSnippetNode"
},
{
"lang": "Swift",
"langSlug": "swift",
"code": "class Solution {\r\n func minimumEffortPath(_ heights: [[Int]]) -> Int {\r\n \r\n }\r\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Go",
"langSlug": "golang",
"code": "func minimumEffortPath(heights [][]int) int {\r\n \r\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Scala",
"langSlug": "scala",
"code": "object Solution {\r\n def minimumEffortPath(heights: Array[Array[Int]]): Int = {\r\n \r\n }\r\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Kotlin",
"langSlug": "kotlin",
"code": "class Solution {\r\n fun minimumEffortPath(heights: Array<IntArray>): Int {\r\n \r\n }\r\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "Rust",
"langSlug": "rust",
"code": "impl Solution {\r\n pub fn minimum_effort_path(heights: Vec<Vec<i32>>) -> i32 {\r\n \r\n }\r\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "PHP",
"langSlug": "php",
"code": "class Solution {\r\n\r\n /**\r\n * @param Integer[][] $heights\r\n * @return Integer\r\n */\r\n function minimumEffortPath($heights) {\r\n \r\n }\r\n}",
"__typename": "CodeSnippetNode"
},
{
"lang": "TypeScript",
"langSlug": "typescript",
"code": "function minimumEffortPath(heights: number[][]): number {\r\n\r\n};",
"__typename": "CodeSnippetNode"
},
{
"lang": "Racket",
"langSlug": "racket",
"code": "(define/contract (minimum-effort-path heights)\r\n (-> (listof (listof exact-integer?)) exact-integer?)\r\n\r\n )",
"__typename": "CodeSnippetNode"
}
],
2022-05-02 23:44:12 +08:00
"stats": "{\"totalAccepted\": \"74.7K\", \"totalSubmission\": \"143.7K\", \"totalAcceptedRaw\": 74712, \"totalSubmissionRaw\": 143694, \"acRate\": \"52.0%\"}",
2022-03-27 18:27:43 +08:00
"hints": [
"Consider the grid as a graph, where adjacent cells have an edge with cost of the difference between the cells.",
"If you are given threshold k, check if it is possible to go from (0, 0) to (n-1, m-1) using only edges of ≤ k cost.",
"Binary search the k value."
],
"solution": {
"id": "1036",
"canSeeDetail": false,
"paidOnly": true,
"hasVideoSolution": false,
"paidOnlyVideo": true,
"__typename": "ArticleNode"
},
"status": null,
"sampleTestCase": "[[1,2,2],[3,8,2],[5,3,5]]",
"metaData": "{\n \"name\": \"minimumEffortPath\",\n \"params\": [\n {\n \"name\": \"heights\",\n \"type\": \"integer[][]\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n }\n}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [],
"enableRunCode": true,
"enableTestMode": false,
"enableDebugger": true,
"envInfo": "{\"cpp\": [\"C++\", \"<p>Compiled with <code> clang 11 </code> using the latest C++ 17 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level two optimization (<code>-O2</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\"], \"java\": [\"Java\", \"<p><code> OpenJDK 17 </code>. Java 8 features such as lambda expressions and stream API can be used. </p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n<p>Includes <code>Pair</code> class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.</p>\"], \"python\": [\"Python\", \"<p><code>Python 2.7.12</code>.</p>\\r\\n\\r\\n<p>Most libraries are already imported automatically for your convenience, such as <a href=\\\"https://docs.python.org/2/library/array.html\\\" target=\\\"_blank\\\">array</a>, <a href=\\\"https://docs.python.org/2/library/bisect.html\\\" target=\\\"_blank\\\">bisect</a>, <a href=\\\"https://docs.python.org/2/library/collections.html\\\" target=\\\"_blank\\\">collections</a>. If you need more libraries, you can import it yourself.</p>\\r\\n\\r\\n<p>For Map/TreeMap data structure, you may use <a href=\\\"http://www.grantjenks.com/docs/sortedcontainers/\\\" target=\\\"_blank\\\">sortedcontainers</a> library.</p>\\r\\n\\r\\n<p>Note that Python 2.7 <a href=\\\"https://www.python.org/dev/peps/pep-0373/\\\" target=\\\"_blank\\\">will not be maintained past 2020</a>. For the latest Python, please choose Python3 instead.</p>\"], \"c\": [\"C\", \"<p>Compiled with <code>gcc 8.2</code> using the gnu99 standard.</p>\\r\\n\\r\\n<p>Your code is compiled with level one optimization (<code>-O1</code>). <a href=\\\"https://github.com/google/sanitizers/wiki/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer</a> is also enabled to help detect out-of-bounds and use-after-free bugs.</p>\\r\\n\\r\\n<p>Most standard library headers are already included automatically for your convenience.</p>\\r\\n\\r\\n<p>For hash table operations, you may use <a href=\\\"https://troydhanson.github.io/uthash/\\\" target=\\\"_blank\\\">uthash</a>. \\\"uthash.h\\\" is included by default. Below are some examples:</p>\\r\\n\\r\\n<p><b>1. Adding an item to a hash.</b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; /* we'll use this field as the key */\\r\\n char name[10];\\r\\n UT_hash_handle hh; /* makes this structure hashable */\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>2. Looking up an item in a hash:</b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n</pre>\\r\\n</p>\\r\\n\\r\\n<p><b>3. Deleting an item in a hash:</b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n</pre>\\r\\n</p>\"], \"csharp\": [\"C#\", \"<p><a href=\\\"https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9\\\" target=\\\"_blank\\\">C# 10 with .NET 6 runtime</a></p>\\r\\n\\r\\n<p>Your code is compiled with debug flag enabled (<code>/debug</code>).</p>\"], \"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 <a href=\\\"https://github.com/datastructures-js/priority-queue\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and <a href=\\\"https:
"libraryUrl": null,
"adminUrl": null,
2022-05-02 23:44:12 +08:00
"challengeQuestion": {
"id": "892",
"date": "2022-04-28",
"incompleteChallengeCount": 0,
"streakCount": 0,
"type": "DAILY",
"__typename": "ChallengeQuestionNode"
},
2022-03-27 18:27:43 +08:00
"__typename": "QuestionNode"
}
}
}