Skip to content

0063 issue, python file added #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Python/0063.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Solution:
def uniquePathsWithObstacles(self, obstacleGrid: List[List[int]]) -> int:
#m rows, n cols

m = len(obstacleGrid)
n = len(obstacleGrid[0])

if m<0 or n<0 or obstacleGrid[0][0] == 1:
return 0

dp = [[0 for i in range(n)] for j in range(m)]

dp[0][0] = 1

for col in range(1, n):
dp[0][col] = dp[0][col-1] if obstacleGrid[0][col] != 1 else 0

for row in range(1, m):
dp[row][0] = dp[row-1][0] if obstacleGrid[row][0] != 1 else 0

for row in range(1, m):
for col in range(1, n):
dp[row][col] = dp[row-1][col] + dp[row][col-1] if obstacleGrid[row][col] != 1 else 0

return dp[m-1][n-1]


tiume - O(mn)
space - O(mn)

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Or from the Sheet 1 of this [Google Sheet](https://bit.ly/2EUhwnw)
| 0053 | [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) | Parse array and save the best solution at each step | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0053.java) [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0053.py) | O(n) | O(1) | Easy | Array Dynamic Programming | [📺](https://www.youtube.com/watch?v=vkLpz2YF8Rc) |
| 0055 | [Jump Game](https://leetcode.com/problems/jump-game/) | Iterate from last index and check if we can reach there from current index or not | [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0055.py) | O(n) | O(1) | Medium | Array Greedy | [📺](https://www.youtube.com/watch?v=ymET7SJsDQc) |
| 0062| [Unique Paths (Total no of unique paths in m x n matrix)](https://leetcode.com/problems/unique-paths/) | As the first element in each row will always be 1, so maintaining one row is enough to reach bottom-right corner of the grid | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0062.java) [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0062.py) | O(n) | O(1) | Medium |Array Dynamic Programming | |
| 0063| [Unique Paths II (Total no of unique paths in m x n matrix with obstacles)](https://leetcode.com/problems/unique-paths-ii/) | Create a 2D matrix of same size of the given matrix to store the results.Traverse through the created array row wise and start filling the values in it.If an obstacle is found, set the value to 0.For the first row and column, set the value to 1 if obstacle is not found.Set the sum of the right and the upper values if obstacle is not present at that corresponding position in the given matirx. Return the last value of the created 2d matrix. As the first element in each row will always be 1, so maintaining one row is enough to reach bottom-right corner of the grid | [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0063.py) | O(mn) | O(mn) | Medium |Array Dynamic Programming | [📺](https://www.youtube.com/watch?v=QrdLXzlefSM) |
| 0070 | [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | steps[n]=steps[n-1]+steps[n-2]. | [C++](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/C++/0070.cpp) [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0070.py) | O(n) | O(1) | Easy | Dynamic Programming | [📺](https://www.youtube.com/watch?v=QiD2Hbwx2z0) |
| 0072 | [Edit Distance](https://leetcode.com/problems/edit-distance/) | minDis(i,j)=min(minDis(i-1,j),minDis(i,j-1),minDis(i-1,j-1))+1; | [Java](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Java/0072.py) | O(m*n) | O(m*n) | Hard | String Dynamic programming |
| 0073 | [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) | Use the first cell of every row and column as a flag. This flag would determine whether a row or column has been set to zero. | [C++](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/C++/0073.cpp) [Python](https://github.com/sankalpdayal5/LeetCode-Solutions/blob/master/Python/0073.py) | O(m*n) | O(1) | Medium | Array | [📺](https://www.youtube.com/watch?v=W1I7slnETp4) |
Expand Down