Browser tab content: Breadth-First Search 0 Debugging... Run Submit 00:00:00 Description…
- User
Browser tab content: Breadth-First Search 0 Debugging... Run Submit 00:00:00 Description Editorial Editorial Solutions Solutions Submissions Submissions Debugger Debugger Code Note Note Testcase Testcase Test Result 200. Number of Islands Solved Medium Topics Companies
Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.
An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.
Example 1:
Input: grid = [ ["1","1","1","1","0"], ["1","1","0","1","0"], ["1","1","0","0","0"], ["0","0","0","0","0"] ] Output: 1
Example 2:
Input: grid = [ ["1","1","0","0","0"], ["1","1","0","0","0"], ["0","0","1","0","0"], ["0","0","0","1","1"] ] Output: 3
Constraints:
m == grid.length n == grid[i].length 1 <= m, n <= 300 grid[i][j] is '0' or '1'. Seen this question in a real interview before? 1/5 Yes No Accepted 3.1M Submissions 5M Acceptance Rate 60.8% Topics Array Depth-First Search Breadth-First Search Union Find Matrix Companies 0 - 3 months Amazon 36 Google 27 Meta 21 Bloomberg 17 Uber 15 TikTok 14 Microsoft 13 Apple 11 Oracle 7 Anduril 6 0 - 6 months Yandex 6 LinkedIn 5 Samsung 5 Adobe 4 Nvidia 4 PayPal 4 Tinkoff 3 Zoho 3 Whatnot 3 Walmart Labs 2 6 months ago Goldman Sachs 18 Tesla 9 Yahoo 9 Intel 7 ByteDance 6 Flipkart 5 eBay 5 Snap 5 Salesforce 5 Cisco 4 Similar Questions Surrounded Regions Medium Walls and Gates Medium Number of Islands II Hard Number of Connected Components in an Undirected Graph Medium Battleships in a Board Medium Number of Distinct Islands Medium Max Area of Island Medium Count Sub Islands Medium Find All Groups of Farmland Medium Count Unreachable Pairs of Nodes in an Undirected Graph Medium Maximum Number of Fish in a Grid Medium Discussion (227) Choose a type Preview Comment 💡 Discussion Rules
-
Please don't post any solutions in this discussion.
-
The problem discussion is for asking questions about the problem or for sharing tips - anything except for solutions.
-
If you'd like to share your solution for feedback and ideas, please head to the solutions tab and post it there.
Sort by:Best No comments yet. 1 2 3 4 5 6 23 Copyright ©️ 2024 LeetCode All rights reserved 23.2K 227 149 Online Java Auto 1 2 3 4 5 class Solution { public int numIslands(char[][] grid) { } } Saved Ln 3, Col 9 Compile Error Line 4: error: incompatible types: char[] cannot be converted to int for (int num : nums) { ^
Breadth-First Search Filter
Remove distracting text, extract the programming question, provide simple, common, and optimized Java solution for it.
-
- Assistant