title stringlengths 1 100 | titleSlug stringlengths 3 77 | Java int64 0 1 | Python3 int64 1 1 | content stringlengths 28 44.4k | voteCount int64 0 3.67k | question_content stringlengths 65 5k | question_hints stringclasses 970
values |
|---|---|---|---|---|---|---|---|
Python3 Solution | unique-paths-ii | 0 | 1 | \n```\nclass Solution:\n def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n m=len(obstacleGrid)\n n=len(obstacleGrid[0])\n dp=[[0 for _ in range(n)] for _ in range(m)]\n for col in range(n):\n if obstacleGrid[0][col]==1:\n break\n ... | 3 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Well Explained , Slow ass DFS | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe use recursive DFS with memoization (2D array) and initialize with setting the destination value to 1\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCheck out the Populated grid here :\n\n[7, 3, 3, 1]\n[4, 0, 2,... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Well Explained , Slow ass DFS | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe use recursive DFS with memoization (2D array) and initialize with setting the destination value to 1\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCheck out the Populated grid here :\n\n[7, 3, 3, 1]\n[4, 0, 2,... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Less no of line code with python | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Less no of line code with python | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Python 13 lines | unique-paths-ii | 0 | 1 | # Code\n```\nclass Solution:\n def uniquePathsWithObstacles(self, A: List[List[int]]) -> int:\n if A[0][0] or A[-1][-1]:\n return 0\n rangeN, rangeM, source = range(len(A)), range(len(A[0])), [(-1, 0), (0, -1)]\n A[0][0] = -1\n for i, j, (_i, _j) in product(rangeN, rangeM, sour... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Python 13 lines | unique-paths-ii | 0 | 1 | # Code\n```\nclass Solution:\n def uniquePathsWithObstacles(self, A: List[List[int]]) -> int:\n if A[0][0] or A[-1][-1]:\n return 0\n rangeN, rangeM, source = range(len(A)), range(len(A[0])), [(-1, 0), (0, -1)]\n A[0][0] = -1\n for i, j, (_i, _j) in product(rangeN, rangeM, sour... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
PYTHON CODE || using MEMOIZATION | unique-paths-ii | 0 | 1 | \n```\nclass Solution:\n def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n memo={}\n def uniquePathsWithObstacleHelper(i,j,obstacleGrid):\n if i==len(obstacleGrid)-1 and j==len(obstacleGrid[0])-1 and obstacleGrid[i][j]==1:\n return 0\n if i... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
PYTHON CODE || using MEMOIZATION | unique-paths-ii | 0 | 1 | \n```\nclass Solution:\n def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n memo={}\n def uniquePathsWithObstacleHelper(i,j,obstacleGrid):\n if i==len(obstacleGrid)-1 and j==len(obstacleGrid[0])-1 and obstacleGrid[i][j]==1:\n return 0\n if i... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Binbin is undefeatable! | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Binbin is undefeatable! | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Ex-Amazon explains a solution with Python, JavaScript, Java and C++ | unique-paths-ii | 1 | 1 | # Intuition\nMain goal is to determine the count of unique paths from the top-left corner to the bottom-right corner of a grid while accounting for obstacles in the grid. It uses dynamic programming to iteratively calculate the paths, avoiding obstacles and utilizing previously computed values to efficiently arrive at ... | 15 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Ex-Amazon explains a solution with Python, JavaScript, Java and C++ | unique-paths-ii | 1 | 1 | # Intuition\nMain goal is to determine the count of unique paths from the top-left corner to the bottom-right corner of a grid while accounting for obstacles in the grid. It uses dynamic programming to iteratively calculate the paths, avoiding obstacles and utilizing previously computed values to efficiently arrive at ... | 15 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
✅ 100% Dynamic Programming [VIDEO] - Optimal Solution | unique-paths-ii | 1 | 1 | # Problem Understanding\n\nIn the "Unique Paths II" problem, we are presented with a grid filled with obstacles and open paths. Starting from the top-left corner, the goal is to find the number of unique paths that lead to the bottom-right corner. We can only move right or down at any point in time. If a cell has an ob... | 50 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
✅ 100% Dynamic Programming [VIDEO] - Optimal Solution | unique-paths-ii | 1 | 1 | # Problem Understanding\n\nIn the "Unique Paths II" problem, we are presented with a grid filled with obstacles and open paths. Starting from the top-left corner, the goal is to find the number of unique paths that lead to the bottom-right corner. We can only move right or down at any point in time. If a cell has an ob... | 50 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Python easy solutions | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nSame as unique path solution. But we do just one thing that, where the obstacle is there we assign it to zero and calculate further. \n\n# Complexity\n- Time complexity:\nO(m*n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nc... | 2 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Python easy solutions | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nSame as unique path solution. But we do just one thing that, where the obstacle is there we assign it to zero and calculate further. \n\n# Complexity\n- Time complexity:\nO(m*n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nc... | 2 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Python DP + Memo | unique-paths-ii | 0 | 1 | ## Code\n```\nclass Solution:\n def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n m=len(obstacleGrid)\n n=len(obstacleGrid[0])\n dp=[[0 for _ in range(n)] for _ in range(m)]\n dp[0][0]=1 - obstacleGrid[0][0]\n for i in range(m):\n for j in range... | 2 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Python DP + Memo | unique-paths-ii | 0 | 1 | ## Code\n```\nclass Solution:\n def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n m=len(obstacleGrid)\n n=len(obstacleGrid[0])\n dp=[[0 for _ in range(n)] for _ in range(m)]\n dp[0][0]=1 - obstacleGrid[0][0]\n for i in range(m):\n for j in range... | 2 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Python short and clean. Multiple solutions. | unique-paths-ii | 0 | 1 | # Approach 1: Top-Down DP\n\n# Complexity\n- Time complexity: $$O(m \\cdot n)$$\n\n- Space complexity: $$O(m \\cdot n)$$\n\n# Code\n```python\nclass Solution:\n def uniquePathsWithObstacles(self, grid: list[list[int]]) -> int:\n m, n = len(grid), len(grid[0])\n end = (m - 1, n - 1)\n\n @cache\n ... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Python short and clean. Multiple solutions. | unique-paths-ii | 0 | 1 | # Approach 1: Top-Down DP\n\n# Complexity\n- Time complexity: $$O(m \\cdot n)$$\n\n- Space complexity: $$O(m \\cdot n)$$\n\n# Code\n```python\nclass Solution:\n def uniquePathsWithObstacles(self, grid: list[list[int]]) -> int:\n m, n = len(grid), len(grid[0])\n end = (m - 1, n - 1)\n\n @cache\n ... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Beats 90.79% 63. Unique Paths II with step by step explanation | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Create a 2D dp list with the size of m+1 x n+1, with all elements initialized as 0.\n2. Set dp[0][1] to 1 as it is the starting point for the robot.\n3. Loop through the grid, if the current element is not an obstacle (ob... | 3 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Beats 90.79% 63. Unique Paths II with step by step explanation | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Create a 2D dp list with the size of m+1 x n+1, with all elements initialized as 0.\n2. Set dp[0][1] to 1 as it is the starting point for the robot.\n3. Loop through the grid, if the current element is not an obstacle (ob... | 3 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Finding Unique Paths in a Grid with Obstacles: A Dynamic Programming Approach | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires us to find the number of unique paths from the top-left corner of a matrix to the bottom-right corner. The matrix contains obstacles which are represented by 1 and free spaces represented by 0. If there is an obstacle... | 15 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Finding Unique Paths in a Grid with Obstacles: A Dynamic Programming Approach | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem requires us to find the number of unique paths from the top-left corner of a matrix to the bottom-right corner. The matrix contains obstacles which are represented by 1 and free spaces represented by 0. If there is an obstacle... | 15 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Python || 99.01% Faster || DP || Memoization+Tabulation | unique-paths-ii | 0 | 1 | ```\n#Recursion \n#Time Complexity: O(2^(m+n))\n#Space Complexity: O(n)\nclass Solution1: \n def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n def solve(i,j):\n if obstacleGrid[i][j]:\n return 0\n if i==0 and j==0:\n return 1\n ... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Python || 99.01% Faster || DP || Memoization+Tabulation | unique-paths-ii | 0 | 1 | ```\n#Recursion \n#Time Complexity: O(2^(m+n))\n#Space Complexity: O(n)\nclass Solution1: \n def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:\n def solve(i,j):\n if obstacleGrid[i][j]:\n return 0\n if i==0 and j==0:\n return 1\n ... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
Simple solution using dp | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
... |
Simple solution using dp | unique-paths-ii | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are given an `m x n` integer array `grid`. There is a robot initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
An obstacle and space are marked as ... | The robot can only move either down or right. Hence any cell in the first row can only be reached from the cell left to it. However, if any cell has an obstacle, you don't let that cell contribute to any path. So, for the first row, the number of ways will simply be
if obstacleGrid[i][j] is not an obstacle
obst... |
✅✅Python🔥Java 🔥C++🔥Simple Solution🔥Easy to Understand🔥 | minimum-path-sum | 1 | 1 | # Please UPVOTE \uD83D\uDC4D\n\n**!! BIG ANNOUNCEMENT !!**\nI am currently Giving away my premium content well-structured assignments and study materials to clear interviews at top companies related to computer science and data science to my current Subscribers this week. I planned to give for next 10,000 Subscribers a... | 288 | Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
**Note:** You can only move either down or right at any point in time.
**Example 1:**
**Input:** grid = \[\[1,3,1\],\[1,5,1\],\[4,2,1\]\]
**Output:** 7
**Explanat... | null |
Python Dijikstra Algo | O(n*m*log(n*m) | Code for reference | minimum-path-sum | 0 | 1 | \n```\n def minPathSum(self, grid: List[List[int]]) -> int:\n direc = [[1,0],[0,1]] # only down and right\n n,m = len(grid),len(grid[0])\n dist = [ [n*m*100 for _ in range(0,m)] for _ in range(0,n) ]\n dist[0][0] = grid[0][0]\n heap = [ [grid[0][0],0,0] ] #dist,point\n\n while(len(heap)>... | 1 | Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
**Note:** You can only move either down or right at any point in time.
**Example 1:**
**Input:** grid = \[\[1,3,1\],\[1,5,1\],\[4,2,1\]\]
**Output:** 7
**Explanat... | null |
Dynamic Programming: Finding the Minimum Path Sum in a Grid | minimum-path-sum | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nThe problem asks to find the minimum sum of a path from the top-left corner to the bottom-right corner of a grid. Since we are only allowed to move right and down, the possible paths we can take are limited. Hence, we can use dynamic pr... | 9 | Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
**Note:** You can only move either down or right at any point in time.
**Example 1:**
**Input:** grid = \[\[1,3,1\],\[1,5,1\],\[4,2,1\]\]
**Output:** 7
**Explanat... | null |
python top down and bottom up approach with explanation | minimum-path-sum | 0 | 1 | \n## Intuition\nThink of how to solve this problem using recursion. if your current position is x, y ; you can go either x+1, y or x, y+1. you need to take the minimum sum of these 2 traversals\n\n## Top down Approach\n<!-- Describe your approach to solving the problem. -->\nIn Top down approach, as explained in intuit... | 2 | Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
**Note:** You can only move either down or right at any point in time.
**Example 1:**
**Input:** grid = \[\[1,3,1\],\[1,5,1\],\[4,2,1\]\]
**Output:** 7
**Explanat... | null |
✅Python3 || C++✅ DP ( 91 ms || Beats 94.21%) | minimum-path-sum | 0 | 1 | This code is an implementation of the minimum path sum problem on a 2D grid. The problem requires finding the minimum sum of numbers along a path from the top-left corner to the bottom-right corner of the grid.\n\nThe function takes a 2D list of integers grid as input, which represents the values in the grid. The funct... | 51 | Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
**Note:** You can only move either down or right at any point in time.
**Example 1:**
**Input:** grid = \[\[1,3,1\],\[1,5,1\],\[4,2,1\]\]
**Output:** 7
**Explanat... | null |
Image Explanation🏆- [Recursion - DP (4 Methods)] - C++/Java/Python | minimum-path-sum | 1 | 1 | # Video Solution (`Aryan Mittal`)\n`Minimum Path Sum` by `Aryan Mittal`\n\n\n\n# Approach & Intution\n {\n return is_valid_number(s);\n }\n\nbool is_valid_number(const std::string& s) {\n if (s.empty()) return false;\n\n size_t i = 0;\n if (s[i] == \'+\' || s[i] == \'-\') i++;\n\n bool has_integer_part = false;\n while (i < s.size... | 13 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
Python Simple Solution Beats 100% | valid-number | 0 | 1 | # Intuition\nUsed try and except method.\n\n# Approach\nSimply used except block when getting error in try block while typecasting string to integer\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution:\n def isNumber(self, s: str) -> bool:\n try:\n ... | 5 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
Python 3 Regex with example | valid-number | 0 | 1 | If you want to practice regex, regex101.com is a good site\n```\nclass Solution:\n def isNumber(self, s: str) -> bool:\n\t\t#Example: +- 1 or 1. or 1.2 or .2 e or E +- 1 \n engine = re.compile(r"^[+-]?((\\d+\\.?\\d*)|(\\d*\\.?\\d+))([eE][+-]?\\d+)?$")\n return engine.match(s.str... | 67 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
Very fast and easy to understand solution (without python built-in tools) | valid-number | 0 | 1 | ```\nclass Solution:\n r"""\n Idea: split the input by the e or E and follow the validation rule"""\n def is_uinteger(self, st):\n if st=="": return False\n return set(st).issubset("0123456789")\n def is_integer(self,st):\n if st=="": return False\n if st[0] in "+-":\n ... | 5 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
28ms Beats 98.80% | O(n) |Explanation | valid-number | 0 | 1 | # Intuition\nThe code is designed to determine whether a given string represents a valid numeric value according to certain rules. The primary components to consider are the part before \'e\' (if present), the part after \'e\' (if present), the presence of a sign (\'+\' or \'-\') at the beginning, and the use of a deci... | 1 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
Beats 98% in runtime & 100% in memory | valid-number | 0 | 1 | \nPlease !!!!!!!!!!!!!!\n\n\n```\nclass Solution:\n def isNumber(self, s: str) -> bool:\n if s==\'inf\' or s==\'-inf\' or s==\'+inf\' or s==\'Infinity\' or s==\'+Infinity\' or s==\'-Infinity\' or s==\'nan\':return False\n try:num=float(s);return True\n except:return False\n``` | 3 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
python3 Very easy Solution | valid-number | 0 | 1 | \n```\nclass Solution:\n def isNumber(self,s:str)->bool:\n try:\n float(s)\n except:\n return False\n\n return "inf" not in s.lower() \n``` | 3 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
Python3 DFA | valid-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse DFA\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n\n\n# Code\n```\nclass Solution:\n de... | 4 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
65. Valid Number | valid-number | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThis solution uses a simple approach to keep track of different components of the number and validate each one according to the rules mentioned in the problem statement. The time complexity of this solution is O(n) where n i... | 3 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
Python3 beating 94.83% Easiest Smallest Understandable Solution | valid-number | 0 | 1 | \n\n\n# Code\n```\nclass Solution:\n def isNumber(self,s:str)->bool:\n try:\n float(s)\n except:\n return False\n return "inf" not in s.lower() \n... | 2 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
[Python3] dfa | valid-number | 0 | 1 | This solution is based on [this thread](https://leetcode.com/problems/valid-number/discuss/23728/A-simple-solution-in-Python-based-on-DFA) which is by far the most inspirational solution that I\'ve found on LC. Please upvote that thread if you like this implementation. \n\n```\nclass Solution:\n def isNumber(self, s... | 11 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
Simple Python Solution (faster than 95%) (4 lines) | valid-number | 0 | 1 | Using try and except block in the question makes it extremely simple to handle.\nBasically, **just return True if float of the string exists, else the compiler will throw an error which will be caught by the except block, where we can return False.**\n```\nclass Solution:\n def isNumber(self, s: str) -> bool:\n ... | 8 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
[Python3] Solutions with explanation | valid-number | 0 | 1 | Initialize the flags **dot**, **exp** and **digit** to keep track of whether the current token being parsed is a decimal point, exponent, or digit, respectively. Then loop over the each character in the input string s and check the conditions from the **task description**.\n```\nclass Solution:\n def isNumber(self, ... | 2 | A **valid number** can be split up into these components (in order):
1. A **decimal number** or an **integer**.
2. (Optional) An `'e'` or `'E'`, followed by an **integer**.
A **decimal number** can be split up into these components (in order):
1. (Optional) A sign character (either `'+'` or `'-'`).
2. One of the... | null |
Python 98.30 % beats || 2 Approachs || Simple Code | plus-one | 0 | 1 | # Your upvote is my motivation!\n\n# Code\n# Approach 1 (Array) -> 98.30 % beats\n```\nclass Solution:\n def plusOne(self, digits: List[int]) -> List[int]:\n\n for i in range(len(digits)-1, -1, -1):\n if digits[i] == 9:\n digits[i] = 0\n else:\n digits[i] = ... | 38 | You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the `ith` digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
Increment the large integer by one and re... | null |
On Fire Python Solution! | plus-one | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n converting into string and int and so\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n iterated over list and calculate edge cases \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.... | 0 | You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the `ith` digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
Increment the large integer by one and re... | null |
One `for` loop beats 93% | plus-one | 0 | 1 | # Code\n```\nclass Solution:\n def plusOne(self, digits: List[int]) -> List[int]:\n\n for i in range(len(digits)-1,-1,-1):\n if digits[i]==9:\n digits[i]=0\n else:\n digits[i]+=1\n return digits\n return [1]+digits\n``` | 27 | You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the `ith` digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
Increment the large integer by one and re... | null |
Simplest Python Approach - Beats 99.5% | plus-one | 0 | 1 | # Intuition\nOften the obvious approach is among the best. If you just convert to an integer and add one, it beats 98% of solutions.\n\n# Approach\nInstead of looping across the list and accounting for random 9s, just convert to an integer and add one. Then convert back to a list.\n\n# Complexity\nThe time complexity ... | 40 | You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the `ith` digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
Increment the large integer by one and re... | null |
✅ Python || Time Complexity O(n) || Beats 98.26% in Python3 || Using Iteration ✔ | plus-one | 0 | 1 | # Intuition\nUsing Iteration form n-1 to 0\n\nWe have to add 1 in given digit ( given array ) , so we simple iterate form last index (n-1) to first index (0) and will check if we add (+1) or not , ( (if(digits[i] == 9)) if current element is 9 then we can\'t add directly )\n\nif not (means digits[i] == 9 ) then we mak... | 6 | You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the `ith` digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
Increment the large integer by one and re... | null |
Simple easy Solution in Python3 | plus-one | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def plusOne(self, digits: List[int]) -> List[int]:\n s= \'\'.join(map(str,digits))\n i=int(s)+1\n li=list(map(int,str(i))) \n return li\n``` | 5 | You are given a **large integer** represented as an integer array `digits`, where each `digits[i]` is the `ith` digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading `0`'s.
Increment the large integer by one and re... | null |
1ms (Beats 100%)🔥🔥|| Full Explanation✅|| Append & Reverse✅|| C++|| Java|| Python3 | add-binary | 1 | 1 | # Intuition :\n- We have to add two binary numbers (made up of 0\'s and 1\'s) and returns the result in binary.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach :\n- We start at the right end of each binary number, adding the digits and any carry-over value, and storing the result in a... | 487 | Given two binary strings `a` and `b`, return _their sum as a binary string_.
**Example 1:**
**Input:** a = "11", b = "1"
**Output:** "100"
**Example 2:**
**Input:** a = "1010", b = "1011"
**Output:** "10101"
**Constraints:**
* `1 <= a.length, b.length <= 104`
* `a` and `b` consist only of `'0'` or `'1'` chara... | null |
one liner beats 85% | add-binary | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def addBinary(self, a: str, b: str) -> str:\n return bin(int(a, 2) + int(b, 2))[2:]\n``` | 1 | Given two binary strings `a` and `b`, return _their sum as a binary string_.
**Example 1:**
**Input:** a = "11", b = "1"
**Output:** "100"
**Example 2:**
**Input:** a = "1010", b = "1011"
**Output:** "10101"
**Constraints:**
* `1 <= a.length, b.length <= 104`
* `a` and `b` consist only of `'0'` or `'1'` chara... | null |
🔥🚀Super Easy Solution🚀||🔥Full Explanation||🔥C++🔥|| Python3 || Java || Commented | add-binary | 1 | 1 | # Consider\uD83D\uDC4D\n```\n Please Upvote If You Find It Helpful\n```\n# Intuition\nLet\'s understand with an example : Addition of 1 and 1 will lead to carry 1 and print 0 , Addition of 1 and 0 give us 1 as carry will lead print 0 , Addition of last remaning carry 1 with no body will lead to print... | 85 | Given two binary strings `a` and `b`, return _their sum as a binary string_.
**Example 1:**
**Input:** a = "11", b = "1"
**Output:** "100"
**Example 2:**
**Input:** a = "1010", b = "1011"
**Output:** "10101"
**Constraints:**
* `1 <= a.length, b.length <= 104`
* `a` and `b` consist only of `'0'` or `'1'` chara... | null |
29 ms python solution( beats 97.90%) | add-binary | 0 | 1 | The function called addBinary takes in two strings, a and b, which represent binary numbers. The function then performs a series of operations to add these two binary numbers together and returns the result as a string.\n\nTo do this, the code first initializes a carry variable to 0, which will be used to store any car... | 1 | Given two binary strings `a` and `b`, return _their sum as a binary string_.
**Example 1:**
**Input:** a = "11", b = "1"
**Output:** "100"
**Example 2:**
**Input:** a = "1010", b = "1011"
**Output:** "10101"
**Constraints:**
* `1 <= a.length, b.length <= 104`
* `a` and `b` consist only of `'0'` or `'1'` chara... | null |
Python 3 || One lines of code || Time 95 % O(1) | add-binary | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis code is a simple implementation of converting binary numbers to integers, adding them, and then converting the sum back to binary. The conversion of binary to integer is done using the int() method with a base of 2, which means that ... | 13 | Given two binary strings `a` and `b`, return _their sum as a binary string_.
**Example 1:**
**Input:** a = "11", b = "1"
**Output:** "100"
**Example 2:**
**Input:** a = "1010", b = "1011"
**Output:** "10101"
**Constraints:**
* `1 <= a.length, b.length <= 104`
* `a` and `b` consist only of `'0'` or `'1'` chara... | null |
STRIVER || C++ || SIGMA || BEGGINER FRIENDLY|| | add-binary | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given two binary strings `a` and `b`, return _their sum as a binary string_.
**Example 1:**
**Input:** a = "11", b = "1"
**Output:** "100"
**Example 2:**
**Input:** a = "1010", b = "1011"
**Output:** "10101"
**Constraints:**
* `1 <= a.length, b.length <= 104`
* `a` and `b` consist only of `'0'` or `'1'` chara... | null |
🔥1 Line using Built-In Functions, With Explanation | add-binary | 0 | 1 | \n# Code\n```\nclass Solution:\n def addBinary(self, a: str, b: str) -> str:\n return bin(int(a, 2) + int(b, 2))[2:]\n\n```\n\n# Explanation\n```\nclass Solution:\n def addBinary(self, a: str, b: str) -> str:\n # Convert binary string \'a\' to an integer.\n int_a = int(a, 2)\n \n ... | 2 | Given two binary strings `a` and `b`, return _their sum as a binary string_.
**Example 1:**
**Input:** a = "11", b = "1"
**Output:** "100"
**Example 2:**
**Input:** a = "1010", b = "1011"
**Output:** "10101"
**Constraints:**
* `1 <= a.length, b.length <= 104`
* `a` and `b` consist only of `'0'` or `'1'` chara... | null |
📌📌Python3 || ⚡28 ms, faster than 93.95% of Python3 | add-binary | 0 | 1 | \n```\nclass Solution:\n def addBinary(self, a: str, b: str) -> str:\n res = []\n carry = 0\n i, j = len(a) - 1, len(b) - 1\n while i >= 0 or j >= 0:\n sum = carry\n ... | 3 | Given two binary strings `a` and `b`, return _their sum as a binary string_.
**Example 1:**
**Input:** a = "11", b = "1"
**Output:** "100"
**Example 2:**
**Input:** a = "1010", b = "1011"
**Output:** "10101"
**Constraints:**
* `1 <= a.length, b.length <= 104`
* `a` and `b` consist only of `'0'` or `'1'` chara... | null |
sol using python - just 2 line | add-binary | 0 | 1 | \n\n# Code\n```\nclass Solution:\n def addBinary(self, a: str, b: str) -> str:\n res = str(bin(int(a, 2) + int(b, 2)))\n return res[2:]\n \n\n\n``` | 6 | Given two binary strings `a` and `b`, return _their sum as a binary string_.
**Example 1:**
**Input:** a = "11", b = "1"
**Output:** "100"
**Example 2:**
**Input:** a = "1010", b = "1011"
**Output:** "10101"
**Constraints:**
* `1 <= a.length, b.length <= 104`
* `a` and `b` consist only of `'0'` or `'1'` chara... | null |
👹 Super Simple Solution, PYTHON🐍 | add-binary | 0 | 1 | # Intuition\nconvert to int, add, back to binary return\n\n\n# Complexity\n- Time complexity:\n O(log n).\n\n- Space complexity:\n O(log n).\n\n# Code\n```\nclass Solution:\n def addBinary(self, a: str, b: str) -> str:\n int_sum = int(a, 2) + int(b, 2)\n binary_sum = bin(int_sum)[2:] #to remove 0b pref... | 2 | Given two binary strings `a` and `b`, return _their sum as a binary string_.
**Example 1:**
**Input:** a = "11", b = "1"
**Output:** "100"
**Example 2:**
**Input:** a = "1010", b = "1011"
**Output:** "10101"
**Constraints:**
* `1 <= a.length, b.length <= 104`
* `a` and `b` consist only of `'0'` or `'1'` chara... | null |
✅ 94.14% 2-Approaches Greedy | text-justification | 1 | 1 | # Interview Problem Understanding\n\nIn interviews, understanding the problem at hand is half the battle. Let\'s break down the "Text Justification" challenge:\n\n**The Scenario**: Imagine you\'re building a word processor, and you need to implement the "Justify" alignment feature. This means that when a user selects a... | 65 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
spaghetti | text-justification | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
Ex-Amazon explains a solution with Python, JavaScript, Java and C++ | text-justification | 1 | 1 | # Intuition\nThe algorithm justifies a given list of words into lines with a specified maximum width. It iterates through the words, adding them to a line if they fit within the width limit, or starts a new line if not. After splitting the text into lines, it evenly distributes extra spaces among words to justify the l... | 12 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
Concise python solution, 10 lines. | text-justification | 0 | 1 | --------------------------------------------\n\n def fullJustify(self, words, maxWidth):\n res, cur, num_of_letters = [], [], 0\n for w in words:\n if num_of_letters + len(w) + len(cur) > maxWidth:\n for i in range(maxWidth - num_of_letters):\n cur[i%(len(cu... | 565 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
Python🔥Java🔥C++🔥Simple Solution | text-justification | 1 | 1 | # ANNOUNCEMENT:\n**Join the discord and don\'t forget to Subscribe the youtube channel to access the premium content materials related to computer science and data science in the discord. (For Only first 10,000 Subscribers)**\n\n**Happy Learning, Cheers Guys \uD83D\uDE0A**\n\n# Click the Link in my Profile to Subscrib... | 10 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
🔥🔥🔥🔥🔥Beats 100% | JS | TS | Java | C++ | C# | C | Python | python3 | Kotlin | PHP 🔥🔥🔥🔥🔥 | text-justification | 1 | 1 | ---\n\n\n---\n```C []\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nchar ** fullJustify(char ** word... | 9 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
One pass, easy to understand with comments | O(n) | text-justification | 0 | 1 | We\'ll build the result array line by line while iterating over words in the input. Whenever the current line gets too big, we\'ll appropriately format it and proceed with the next line until for loop is over. Last but not least, we\'ll need to left-justify the last line.\n\nTime complexity is **O(n)**:\nThere is just ... | 47 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
Python3 Solution | text-justification | 0 | 1 | \n```\nclass Solution:\n def fullJustify(self, words: List[str], maxWidth: int) -> List[str]:\n n=len(words)\n ans=[]\n i=0\n while i<n:\n temp=[]\n seen=0\n cur=""\n while i<n and seen+len(words[i])+len(temp)<=maxWidth:\n temp.ap... | 3 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
Python | Easy to Understand | Fastest | Fully Explained | Concise Solution | text-justification | 0 | 1 | # Python | Easy to Understand | Fastest | Fully Explained | Concise Solution\n```\nclass Solution:\n def fullJustify(self, words: List[str], maxWidth: int) -> List[str]:\n \n result, current_list, num_of_letters = [],[], 0\n # result -> stores final result output\n # current_list -> s... | 2 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
Pox | text-justification | 1 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
68. Text Justification with step by step explanation | text-justification | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | Given an array of strings `words` and a width `maxWidth`, format the text such that each line has exactly `maxWidth` characters and is fully (left and right) justified.
You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that ea... | null |
Fastest solution | sqrtx | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst thing that came to my mind was math module present in Python.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nI imported math module and used its isqrt() function. What it does is basically the calculation of... | 1 | Given a non-negative integer `x`, return _the square root of_ `x` _rounded down to the nearest integer_. The returned integer should be **non-negative** as well.
You **must not use** any built-in exponent function or operator.
* For example, do not use `pow(x, 0.5)` in c++ or `x ** 0.5` in python.
**Example 1:**
... | Try exploring all integers. (Credits: @annujoshi) Use the sorted property of integers to reduced the search space. (Credits: @annujoshi) |
C++ || Binary Search || Easiest Beginner Friendly Sol | sqrtx | 1 | 1 | # Intuition of this Problem:\n<!-- Describe your first thoughts on how to solve this problem. -->\n**NOTE - PLEASE READ APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.**\n\n# Approach for this Problem:\n1. If x is 0, return 0.\n2. Initialize first to 1 a... | 265 | Given a non-negative integer `x`, return _the square root of_ `x` _rounded down to the nearest integer_. The returned integer should be **non-negative** as well.
You **must not use** any built-in exponent function or operator.
* For example, do not use `pow(x, 0.5)` in c++ or `x ** 0.5` in python.
**Example 1:**
... | Try exploring all integers. (Credits: @annujoshi) Use the sorted property of integers to reduced the search space. (Credits: @annujoshi) |
[VIDEO] Step-by-Step Visualization of Binary Search Solution | sqrtx | 0 | 1 | https://youtu.be/1_4xlky3Y2Y?si=6ycdxyKdrj3Zy31b\n\nOne way to solve this would be to check every number starting from 0. Since we could stop once we reach the square root of x, this would run in O(sqrt(n)) time. However, binary search runs in O(log n) time, which, as you can see from the graph below, is superior to ... | 9 | Given a non-negative integer `x`, return _the square root of_ `x` _rounded down to the nearest integer_. The returned integer should be **non-negative** as well.
You **must not use** any built-in exponent function or operator.
* For example, do not use `pow(x, 0.5)` in c++ or `x ** 0.5` in python.
**Example 1:**
... | Try exploring all integers. (Credits: @annujoshi) Use the sorted property of integers to reduced the search space. (Credits: @annujoshi) |
4 Lines of Code--->Binary Search Approach and Normal Approach | sqrtx | 0 | 1 | \n\n# 1. Normal Math Approach\n```\nclass Solution:\n def mySqrt(self, x: int) -> int:\n number=1\n while number*number<=x:\n number+=1\n return number\n\n```\n# Binary Search Approach\n```\n\nclass Solution:\n def mySqrt(self, x: int) -> int:\n left,right=1,x\n while... | 51 | Given a non-negative integer `x`, return _the square root of_ `x` _rounded down to the nearest integer_. The returned integer should be **non-negative** as well.
You **must not use** any built-in exponent function or operator.
* For example, do not use `pow(x, 0.5)` in c++ or `x ** 0.5` in python.
**Example 1:**
... | Try exploring all integers. (Credits: @annujoshi) Use the sorted property of integers to reduced the search space. (Credits: @annujoshi) |
Easy to understand and also Beats 93.18%of users with Python3. | sqrtx | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 0 | Given a non-negative integer `x`, return _the square root of_ `x` _rounded down to the nearest integer_. The returned integer should be **non-negative** as well.
You **must not use** any built-in exponent function or operator.
* For example, do not use `pow(x, 0.5)` in c++ or `x ** 0.5` in python.
**Example 1:**
... | Try exploring all integers. (Credits: @annujoshi) Use the sorted property of integers to reduced the search space. (Credits: @annujoshi) |
Easy python if else solution | sqrtx | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | Given a non-negative integer `x`, return _the square root of_ `x` _rounded down to the nearest integer_. The returned integer should be **non-negative** as well.
You **must not use** any built-in exponent function or operator.
* For example, do not use `pow(x, 0.5)` in c++ or `x ** 0.5` in python.
**Example 1:**
... | Try exploring all integers. (Credits: @annujoshi) Use the sorted property of integers to reduced the search space. (Credits: @annujoshi) |
Python Easy Solution || Binary Search || 100% || | sqrtx | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity \n- Time complexity: $$O(logn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity ... | 2 | Given a non-negative integer `x`, return _the square root of_ `x` _rounded down to the nearest integer_. The returned integer should be **non-negative** as well.
You **must not use** any built-in exponent function or operator.
* For example, do not use `pow(x, 0.5)` in c++ or `x ** 0.5` in python.
**Example 1:**
... | Try exploring all integers. (Credits: @annujoshi) Use the sorted property of integers to reduced the search space. (Credits: @annujoshi) |
sqrtx | sqrtx | 0 | 1 | # Intuition\nBeats 99.99% more then any Antiseptic strength to kill germs\n\n\n\n# Code\n```\nclass Solution:\n <!-- def mySqrt(self, x: int) -> int:\n return int(x**0.5) -->\n def mySqrt(self, x: int) -> int:\n left=0\n right=10000000\n mid=(left+right)//2\n while(True):\n ... | 2 | Given a non-negative integer `x`, return _the square root of_ `x` _rounded down to the nearest integer_. The returned integer should be **non-negative** as well.
You **must not use** any built-in exponent function or operator.
* For example, do not use `pow(x, 0.5)` in c++ or `x ** 0.5` in python.
**Example 1:**
... | Try exploring all integers. (Credits: @annujoshi) Use the sorted property of integers to reduced the search space. (Credits: @annujoshi) |
✅4 Method's 🤯 || Beat's 100% || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | climbing-stairs | 1 | 1 | # Intuition:\nTo calculate the number of ways to climb the stairs, we can observe that when we are on the nth stair, \nwe have two options: \n1. either we climbed one stair from the (n-1)th stair or \n2. we climbed two stairs from the (n-2)th stair. \n\nBy leveraging this observation, we can break down the problem into... | 1,005 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
C++ || Python || Beats 100% || Using DP || 2 ways (Recursion + memorization , Tabulation, Space Opt) | climbing-stairs | 0 | 1 | # Intuition\nUsing Top - Down Approach -> Recursion + Memorization.\n\n# Approach\nStoring the values of overlapping sub - problems in a vector.\n\n# Complexity\n- Time complexity:\nO(n) -> As we are visiting all values of n atleast 1 time.\n\n- Space complexity:\nO(n) + O(n) - > (Recursive calls + Array of size n)\n\... | 421 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
7 lines of code beats 99.41% very easy solution | climbing-stairs | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Python :Detail explanation (3 solutions easy to difficult) : Recursion, dictionary & DP | climbing-stairs | 0 | 1 | #####\n### General inutution\n##### \t-> Intution : the next distinict way of climbing stairs is euqal to the sum of the last two distinict way of climbing\n##### \t\tdistinct(n) = distinict(n-1) + distinict(n-2)\n##### This intution can be applied using the following three approach --> ordered from easy to difficult a... | 672 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Python3 solution beats 82% (recursion & memoization) | climbing-stairs | 0 | 1 | # Code\n```\nclass Solution:\n def climbStairs(self, n: int) -> int:\n @cache\n def count(n):\n return 1 if n == 1 else 2 if n == 2 else count(n-1) + count(n-2)\n return count(n)\n\n \n``` | 1 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Python easy solution | climbing-stairs | 0 | 1 | # Intuition\nFibonacci Series\n\n# Approach\nPriorly just apply bruteforce method to solve, but get the fibonacci series as a result. So at the end just apply the concept of fibonacci series.\n\nStairs: 1 2 3 4 5 6....\nSteps : 1 2 5 8 13 21...\n\nHere, we see that for climb stair 1 or 2 we have same n numbers... | 1 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Beats 100%. Easiest 1 min explanation in JAVA and Python | climbing-stairs | 1 | 1 | # Intuition & Approach\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal here is to find the number of distinct ways to climb to the top of a staircase with n steps. You can take either one step or two steps at a time.\n\nThe intuition behind this solution is to use dynamic programming to e... | 4 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Dynamic Programming Python3 | climbing-stairs | 0 | 1 | ```\nclass Solution:\n def climbStairs(self, n: int) -> int:\n dp=[-1]*(n+2)\n def solve(i):\n if i==0 or i==1:\n return 1\n if dp[i]!=-1:\n return dp[i]\n left=solve(i-1)\n right=solve(i-2)\n dp[i]=left+right\n ... | 99 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
BEATS 98.5% OF PYTHON SOLUTIONS!!!!! ✅✔☑🔥✅✔☑🔥✅✔☑🔥 | climbing-stairs | 0 | 1 | # Approach\n\n<!-- Describe your first thoughts on how to solve this problem. -->\nusing basic aptitute we can approach this problem by finding the sum of fibonacci series of the given number (n) + 1. To find the total number of ways to climb the stairs.\n\n\n\n# Code\n```\nclass Solution:\n def climbStairs(self, n:... | 2 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Climbing stairs solved through recursion. | climbing-stairs | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 1 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Using Fibonnaci Approach || Climbing Stairs | climbing-stairs | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --... | 3 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Python Easy Solution || 100 % || | climbing-stairs | 0 | 1 | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFind the relation with fibonacci Series.\n\n\nThink it as Fibonacci series.\nLet think about 4 steps.... | 1 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
🎯Optimizing Stair Climbing: From Recursion 🔄 to Dynamic Programming 📊 | climbing-stairs | 0 | 1 | # Intuition \uD83E\uDD14\nThe problem seems similar to the Fibonacci series, where the number of ways to reach the nth stair is the sum of ways to reach the (n-1)th and (n-2)th stair. A naive recursive solution might have a large number of overlapping computations. Thus, dynamic programming principles come into play to... | 2 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Simplest Python DP code. Its basically Fibonacci | climbing-stairs | 0 | 1 | \n# Code\n```\nclass Solution:\n def climbStairs(self, n: int) -> int:\n dp = [0] * (n+1)\n dp[0], dp[1] = 1, 1\n \n for i in range(2, n+1):\n dp[i] = dp[i-1] + dp[i-2]\n \n return dp[n]\n\n``` | 2 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
[VIDEO] Visualization of Bottom-Up Dynamic Programming Approach | climbing-stairs | 0 | 1 | https://www.youtube.com/watch?v=4ikxUxiEB10\n\nSince you can only take 1 step or 2 steps, the total number of ways to climb `n` steps can be defined recursively as: the total number of ways to climb `n-1` stairs + the total number of ways to climb `n-2` stairs. Below is the recursive code:\n\n## Recursive Solution\n``... | 12 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Python | C++ | Easy to Understand | Fastest Solution | C++ runtime - 3ms. | climbing-stairs | 0 | 1 | # *Approach*\n<!-- Describe your approach to solving the problem. -->\n- *When employing dynamic programming, we only need to keep track of the prior and the prior of the prior; otherwise, dp of size n is worthless for further steps.*\n\n# *Complexity*\n- *Time complexity: **O(n)***\n<!-- Add your time complexity here,... | 2 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Beats 70% solution, easy mathematical approach | climbing-stairs | 0 | 1 | # Intuition\niterates from max nums of 2 steps, and min nums of 1 steps\n\n- Time complexity:\n O(n/2 * n/2!)\n- Space complexity:\n O(n)\n\n# Code\n```\nimport operator\nfrom collections import Counter\nfrom math import factorial\n\nclass Solution:\n def climbStairs(self, n: int) -> int:\n #bucket of 1... | 4 | You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
**Example 1:**
**Input:** n = 2
**Output:** 2
**Explanation:** There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
**Example 2:**
... | To reach nth step, what could have been your previous steps? (Think about the step sizes) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.