Skip to content
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

Islands in a Graph #94

Closed
ramitsawhney27 opened this issue Jun 26, 2018 · 15 comments
Closed

Islands in a Graph #94

ramitsawhney27 opened this issue Jun 26, 2018 · 15 comments

Comments

@ramitsawhney27
Copy link
Collaborator

ramitsawhney27 commented Jun 26, 2018

Given:
A grid of size n x m. Each cell is either Red or Blue. Red is denoted as * and . as Blue.
The entire grid is surrounded in blue.
A collection of blue cells surrounded by red on all sides is considered a pool.

Tasks:

  1. Count the total number of pools in the grid.
  2. Return the size of each of the pools in the grid.
  3. Time and Space complexities for each of these operations.

Sample:
5 4

****
*..*
****
*.**
..**

Number of pools: 1; size = 2

@aggmoulik
Copy link

I think 4th row is incomplete

@h-sinha
Copy link
Contributor

h-sinha commented Jun 26, 2018

@ramitsawhney27 it would be really helpful if you update the fourth line of the test case

@ramitsawhney27
Copy link
Collaborator Author

@h-sinha @moulikcipherX fixed.

@h-sinha
Copy link
Contributor

h-sinha commented Jun 27, 2018

Shouldn't the number of pools be 1 in this case? As the '.' in 4th row has a '.' on one side.

@ramitsawhney27
Copy link
Collaborator Author

The two pools are in row 2 and row 4 of size 2 and 1 respectively. The one in the 5th row is not counted.

@lavishsaluja
Copy link
Contributor

@ramitsawhney27 Will like to work on this!

@ghost
Copy link

ghost commented Jul 1, 2018

This is still open, right?

@sahilbansal17
Copy link
Owner

Challenge problems are open for anyone. Whosoever solves and sends the PR earliest, will get the points.

@ghost
Copy link

ghost commented Jul 1, 2018

Yeah I meant to ask whether it has been solved already or not

@ramitsawhney27
Copy link
Collaborator Author

Not yet

@ghost
Copy link

ghost commented Jul 1, 2018

How is the one in the 4th row even a pool? It's not surrounded by red on all sides..

@ramitsawhney27
Copy link
Collaborator Author

I just realized, markdown messes up how it's being shown. Something to do with the \ and *. I've edited it. Ideally, the . should be on the 3rd column in the 4th row. Then the solution is correct for what was given previously.

@ghost
Copy link

ghost commented Jul 1, 2018

Okay, and diagonally blue is okay for a pool?

@ramitsawhney27
Copy link
Collaborator Author

Just keep it as up down left right (4-connectivity) for simplicity.

@ramitsawhney27
Copy link
Collaborator Author

This is solved, closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants