{"id":22513465,"url":"https://github.com/emahtab/unique-paths-ii","last_synced_at":"2026-03-19T23:03:32.979Z","repository":{"id":79525860,"uuid":"396592081","full_name":"eMahtab/unique-paths-ii","owner":"eMahtab","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-22T08:55:39.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-03T17:14:19.562Z","etag":null,"topics":["dynamic-programming","leetcode"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-16T03:04:44.000Z","updated_at":"2024-10-22T08:56:06.000Z","dependencies_parsed_at":"2025-05-27T07:41:11.190Z","dependency_job_id":"265fbe61-1226-40cc-a714-5e174ea6a316","html_url":"https://github.com/eMahtab/unique-paths-ii","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/unique-paths-ii","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Funique-paths-ii","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Funique-paths-ii/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Funique-paths-ii/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Funique-paths-ii/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/unique-paths-ii/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Funique-paths-ii/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28846341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dynamic-programming","leetcode"],"created_at":"2024-12-07T03:12:25.994Z","updated_at":"2026-01-28T15:31:43.801Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unique Paths II\n\n## https://leetcode.com/problems/unique-paths-ii\n\nA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).\n\nThe robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).\n\nNow consider if some obstacles are added to the grids. How many unique paths would there be?\n\nAn obstacle and space is marked as 1 and 0 respectively in the grid.\n\n\n**Algorithm :**\n\n1. If the first cell i.e. obstacleGrid[0,0] contains 1, this means there is an obstacle in the first cell. \nHence the robot won't be able to make any move and we would return the number of ways as 0.\nOtherwise, if obstacleGrid[0,0] has a 0 originally we set it to 1 and move ahead.\n\n2. Iterate the first row. If a cell originally contains a 1, this means the current cell has an obstacle and shouldn't contribute to any path. Hence, set the value of that cell to 0. Otherwise, set it to the value of previous cell i.e. obstacleGrid[i,j] = obstacleGrid[i,j-1]\n\n3. Iterate the first column. If a cell originally contains a 1, this means the current cell has an obstacle and shouldn't contribute to any path. Hence, set the value of that cell to 0. Otherwise, set it to the value of previous cell i.e. obstacleGrid[i,j] = obstacleGrid[i-1,j]\n\n4. Now, iterate through the array starting from cell obstacleGrid[1,1]. If a cell originally doesn't contain any obstacle then the number of ways of reaching that cell would be the sum of number of ways of reaching the cell above it and number of ways of reaching the cell to the left of it.\n obstacleGrid[i,j] = obstacleGrid[i-1,j] + obstacleGrid[i,j-1]\nIf a cell contains an obstacle set it to 0 and continue. This is done to make sure it doesn't contribute to any other path.\n\n\n\n```java\nclass Solution {\n    public int uniquePathsWithObstacles(int[][] obstacleGrid) {\n        int rows = obstacleGrid.length;\n        int cols = obstacleGrid[0].length;\n        if(obstacleGrid == null || obstacleGrid[0][0] == 1)\n          return 0;\n\n        obstacleGrid[0][0] = 1;\n        for(int col = 1; col \u003c cols; col++)\n            obstacleGrid[0][col] = obstacleGrid[0][col] == 1 ? 0 : obstacleGrid[0][col-1];   \n        for(int row = 1; row \u003c rows; row++) \n            obstacleGrid[row][0] = obstacleGrid[row][0] == 1 ? 0 : obstacleGrid[row-1][0];\n            \n        for(int row = 1; row \u003c rows; row++) {\n            for(int col = 1; col \u003c cols; col++) {\n               obstacleGrid[row][col] = obstacleGrid[row][col] == 1 ? 0 :\n                                        obstacleGrid[row][col-1] + obstacleGrid[row-1][col];  \n            }\n        }    \n        return obstacleGrid[rows-1][cols-1];  \n    }\n}\n```\n\n# References :\n\n1. https://leetcode.com/problems/unique-paths-ii/solution\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Funique-paths-ii","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Funique-paths-ii","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Funique-paths-ii/lists"}