Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md
matrixIsland.scala

README.md

Find number of connected 1's in a matrix

Problem

Given a matrix looking like following please find number of connected 1s in it.

Input : mat[][] = {{1, 1, 0, 0, 0},
                   {0, 1, 0, 0, 1},
                   {1, 0, 0, 1, 1},
                   {0, 0, 0, 0, 0},
                   {1, 0, 1, 0, 1}}
Output : 5

Solution

A workign solution in scala is in matrixIsland.scala

 vikrant   ~/vikrantinfo/code/ProblemSolving/matrixIsland     master    scalac matrixIsland.scala                                                          21:20:02  100%    1.95    5.13G 
 vikrant   ~/vikrantinfo/code/ProblemSolving/matrixIsland     master    scala matrixIsland                                                                 21:20:48  100%    1.91    5.12G 
Found a new island 0 0
Found a new island 1 4
Found a new island 4 0
Found a new island 4 2
Found a new island 4 4
5

Read more about it on https://vikrant.info/blog