|
| 1 | +{ |
| 2 | + "problem_name": "trapping_rain_water", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "42", |
| 5 | + "problem_title": "Trapping Rain Water", |
| 6 | + "difficulty": "Hard", |
| 7 | + "topics": "Array, Two Pointers, Dynamic Programming, Stack, Monotonic Stack", |
| 8 | + "tags": ["grind-75"], |
| 9 | + "readme_description": "Given `n` non-negative integers representing an elevation map where the width of each bar is `1`, compute how much water it can trap after raining.", |
| 10 | + "readme_examples": [ |
| 11 | + { |
| 12 | + "content": "\n\n```\nInput: height = [0,1,0,2,1,0,1,3,2,1,2,1]\nOutput: 6\n```\n**Explanation:** The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped." |
| 13 | + }, |
| 14 | + { "content": "```\nInput: height = [4,2,0,3,2,5]\nOutput: 9\n```" } |
| 15 | + ], |
| 16 | + "readme_constraints": "- `n == height.length`\n- `1 <= n <= 2 * 10^4`\n- `0 <= height[i] <= 10^5`", |
| 17 | + "readme_additional": "", |
| 18 | + "solution_imports": "", |
| 19 | + "solution_methods": [ |
| 20 | + { "name": "trap", "parameters": "height: list[int]", "return_type": "int", "dummy_return": "0" } |
| 21 | + ], |
| 22 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution", |
| 23 | + "test_class_name": "TrappingRainWater", |
| 24 | + "test_helper_methods": [ |
| 25 | + { "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" } |
| 26 | + ], |
| 27 | + "test_methods": [ |
| 28 | + { |
| 29 | + "name": "test_trap", |
| 30 | + "parametrize": "height, expected", |
| 31 | + "parametrize_typed": "height: list[int], expected: int", |
| 32 | + "test_cases": "[([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1], 6), ([4, 2, 0, 3, 2, 5], 9), ([3, 0, 2, 0, 4], 7), ([0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1], 6)]", |
| 33 | + "body": "result = self.solution.trap(height)\nassert result == expected" |
| 34 | + } |
| 35 | + ], |
| 36 | + "playground_imports": "from solution import Solution", |
| 37 | + "playground_test_case": "# Example test case\nheight = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]\nexpected = 6", |
| 38 | + "playground_execution": "result = Solution().trap(height)\nresult", |
| 39 | + "playground_assertion": "assert result == expected" |
| 40 | +} |
0 commit comments