{"id":22513761,"url":"https://github.com/emahtab/island-perimeter","last_synced_at":"2026-01-31T18:05:16.794Z","repository":{"id":79525558,"uuid":"231229167","full_name":"eMahtab/island-perimeter","owner":"eMahtab","description":"Island Perimeter","archived":false,"fork":false,"pushed_at":"2020-03-20T01:24:35.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-14T19:11:14.376Z","etag":null,"topics":["island-perimeter","leetcode","problem-solving"],"latest_commit_sha":null,"homepage":null,"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":"2020-01-01T14:56:54.000Z","updated_at":"2020-03-20T01:24:37.000Z","dependencies_parsed_at":"2023-05-10T17:15:32.551Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/island-perimeter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/island-perimeter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fisland-perimeter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fisland-perimeter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fisland-perimeter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fisland-perimeter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/island-perimeter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fisland-perimeter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28949274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T14:26:55.697Z","status":"ssl_error","status_checked_at":"2026-01-31T14:26:52.545Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["island-perimeter","leetcode","problem-solving"],"created_at":"2024-12-07T03:14:22.052Z","updated_at":"2026-01-31T18:05:16.779Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Island Perimeter\n## https://leetcode.com/problems/island-perimeter\n\nYou are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water.\n\nGrid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells).\n\nThe island doesn't have \"lakes\" (water inside that isn't connected to the water around the island). One cell is a square with side length 1. The grid is rectangular, width and height don't exceed 100. Determine the perimeter of the island.\n\n \n\nExample:\n\nInput:\n[[0,1,0,0],\n [1,1,1,0],\n [0,1,0,0],\n [1,1,0,0]]\n\nOutput: 16\n\nExplanation: The perimeter is the 16 yellow stripes in the image below:\n\n![Island Perimeter](island.png?raw=true \"Island Perimeter\")\n\n## Approach :\nWe can solve this problem, by iterating over each element of the 2D grid, and if we see a 1(land), we add its perimeter to the final result. Now to calculate the perimeter of a land, we see its 4 adjacent cells (left, right, up, down). \n\nNote that while calculating the perimeter of a land, only the adjacent cells that are water or if the land's surrounding is outside the grid (remember outside the grid its all water), then only it will add to perimeter.\n\n### Implementation\n\n```java\nclass Solution {\n    public int islandPerimeter(int[][] grid) {\n        if(grid == null || grid.length == 0)\n            return 0;\n        \n        int perimeter = 0;\n        for(int i = 0; i \u003c grid.length; i++) {\n            for(int j = 0; j \u003c grid[i].length; j++) {\n                if(grid[i][j] == 1) {\n                    perimeter += perimeter(grid, i, j);\n                }\n            }\n        }\n        return perimeter;\n    }\n    \n    private int perimeter(int[][] grid, int row, int column) {\n        int perimeter = 0;\n        if(column == 0 || grid[row][column-1] == 0)\n            perimeter++;\n        \n        if(column == grid[row].length-1 || grid[row][column+1] == 0)\n            perimeter++;\n        \n        if(row == 0 || grid[row-1][column] == 0)\n            perimeter++;\n        \n        if(row == grid.length-1 || grid[row+1][column] == 0)\n            perimeter++;\n         \n        return perimeter;    \n    }\n}\n```\nAbove implementation have runtime complexity of O(m * n) and space complexity of O(1), where m is the number of rows in the input grid and n is the number of columns in the input grid.\n\n```\nRuntime Complexity = O(m * n)\nSpace Complexity   = O(1) \n```\n\n## References :\nhttps://massivealgorithms.blogspot.com/2016/11/leetcode-463-island-perimeter.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fisland-perimeter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fisland-perimeter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fisland-perimeter/lists"}