Amazon.com

  www.amazon.com
Work in HR? Unlock Free Profile

Amazon.com Software Development Engineer In Test I (SDET) Interview Question

I interviewed in Seattle, WA and was asked:
"You are given a n*n matrix of bits (1s and 0s) where 1 represents land and 0 represents water. Adjacent 1s can be considered as joined together to form sort of island in water. Count the number of islands. Discuss complexity."
Add Tags [?]
Answer

Part of a Software Development Engineer In Test I (SDET) Interview Review - one of 4,771 Amazon.com Interview Reviews

Answers & Comments

0
of 1
vote

int nCnt = 0;
int land = 0;
boolean bIsOne = false;
int a[rows][cloumns];
int i,j;
for(i = 0;i < rows ; i++)
{
   for(j = 0; j < columns ; j++ )
   {
        if(a[i][j] == 1)
        {
           bIsOne = true;
             nCnt = nCnt +1;
        }
        else
        {
            if(bIsOne == true )
            {
                   if(nCnt > 1)
                   {
                          land ++;
                    }
                    nCnt = 0;
                    bIsOne = false;
            }
        }
    }
}

- Pradnya on Feb 1, 2013

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.