What is your current logic to the problem? I can give you a hint, use a search and iterate through the area until no more connected 1's is found. Don't forget to keep track of where you have already visited. The method could be recursive (easy to implement) or iterative (a bit longer).
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17
Start by figuring out what the steps are at a high level, then figure out how to execute them. Executing them may, and probably will, involve decomposing them into steps which you'll then re-examine in the same way until you have methods which are trivial to execute. Write the trivial methods.
Test.
If results pass tests, done. Else, find and fix bugs.
jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187
Skill Endorsements: 3
So far your breakdown is:
Get the data
Solve the problem somehow for however many grids are submitted.
Report the result.
That middle step needs a little work.
You know you're going to have to solve the problem for one gird, so maybe you should work on that. Solve that, and you should be able to extend it to multiple grids without much trouble.
I'll give you this much for free: it'll look a little like this
private int solve(Grid g) {}
where Grid might be a 2D array or a custom object or whatever structure makes it easiest for you to solve it. Return your solution as an int. When you do multiple grids, you'll stuff that in an array or an ArrayList or whatever makes most sense to you at that point. Don't worry about that now, though, just return the int so you can use it later.
But now you have your solve method to break down.
jon.kiparsky
Posting Virtuoso
1,849 posts since Jun 2010
Reputation Points: 383
Solved Threads: 187
Skill Endorsements: 3