Interview Question
Software DevelopersCountry: India
Interview Type: Written Test
Well assuming that you are getting a matrix of colors for example you'll need to only care about the red and black colors.
public static int CalculateSquares(Color[][] board)
{
Color prev = Color.White;
int xCount = 0;
for(int i = 0;i < board.Length; i++)
{
Color cur = board[i][0];
if(cur != prev && (cur == Color.Black || cur == Color.Red))
{
xCount++;
}
}
prev = Color.White;
int yCount = 0;
for(int i = 0;i < board[0].Length; i++)
{
Color cur = board[0][i];
if(cur != prev && (cur == Color.Black || cur == Color.Red))
{
yCount++;
}
}
return xCount*yCount;
}
- tus124 July 27, 2015