Example 1: [[0,0,1,0,0,0, [0,0,0,0,0,0, [0,1,1,0,1,0,0,0,0,0,0,0,0], [0,1,0,0,1,1,0,0,1,0,1,0,0], [0,1,0,0,1,1,0,0,1,1,1,0,0], [0,0,0,0,0,0,0,0,0,0,1,0,0], [0,0,0,0,0,0,0,1,1,1,0,0,0], [0,0,0,0,0,0,0,1,1,0,0,0,0]] Practice 1 ,0,0,0,0], ,1,0,0,0], Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. Given the above grid, return 6. Note the answer is not 11, because the island must be connected 4-directionally. Find the maximum area of an island in the given 2D array. (If there is no island, the maximum area is 0.) Example 2: [[0,0,0,0,0,0,0,0]] Given the above grid, return 0.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter13: Structures
Section: Chapter Questions
Problem 4PP
icon
Related questions
Question

Please answer the question in the screenshot. Please use the starter code. 

Example 1:
[[0,0,1,0,0,0,0,1,0,0,0,0,0],
[0,0,0,0,0,0,0,1,1,1,0,0,0],
[0,1,1,0,1,0,0,0,0,0,0,0,0],
[0,1,0,0,1,1,0,0,1,0,1,0,0],
[0,1,0,0,1,1,0,0,1,1,1,0,0],
[0,0,0,0,0,0,0,0,0,0,1,0,0],
[0,0,0,0,0,0,0,1,1,1,0,0,0],
[0,0,0,0,0,0,0,1,1,0,0,0,0]]
Practice 1
Given a non-empty 2D array grid of O's
and 1's, an island is a group of 1's
(representing land) connected
4-directionally (horizontal or vertical.)
You may assume all four edges of the
grid are surrounded by water.
Given the above grid, return 6. Note the answer is not 11,
because the island must be connected 4-directionally.
Find the maximum area of an island in
the given 2D array. (If there is no
island, the maximum area is 0.)
Example 2:
[[0,0,0,0,0,0,0,0]]
Given the above grid, return 0.
class Graph {
public int maxAreaofIsland(int[][] grid) {
}
}
Transcribed Image Text:Example 1: [[0,0,1,0,0,0,0,1,0,0,0,0,0], [0,0,0,0,0,0,0,1,1,1,0,0,0], [0,1,1,0,1,0,0,0,0,0,0,0,0], [0,1,0,0,1,1,0,0,1,0,1,0,0], [0,1,0,0,1,1,0,0,1,1,1,0,0], [0,0,0,0,0,0,0,0,0,0,1,0,0], [0,0,0,0,0,0,0,1,1,1,0,0,0], [0,0,0,0,0,0,0,1,1,0,0,0,0]] Practice 1 Given a non-empty 2D array grid of O's and 1's, an island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. Given the above grid, return 6. Note the answer is not 11, because the island must be connected 4-directionally. Find the maximum area of an island in the given 2D array. (If there is no island, the maximum area is 0.) Example 2: [[0,0,0,0,0,0,0,0]] Given the above grid, return 0. class Graph { public int maxAreaofIsland(int[][] grid) { } }
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Hyperlinks
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr