Skip to content

Instantly share code, notes, and snippets.

@bejado
Last active October 13, 2017 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bejado/e77b540f06f86885f711ebb56d369c14 to your computer and use it in GitHub Desktop.
Save bejado/e77b540f06f86885f711ebb56d369c14 to your computer and use it in GitHub Desktop.
C interview question for Snap Inc.
#import <Foundation/Foundation.h>
static const int GRID_WIDTH = 10;
static const int GRID_HEIGHT = 10;
void printGrid(bool grid[GRID_WIDTH][GRID_HEIGHT]) {
for (int row = 0; row < GRID_HEIGHT; row++) {
for (int col = 0; col < GRID_WIDTH; col++) {
printf(grid[row][col] ? "x" : ".");
}
printf("\n");
}
}
void floodFill(bool grid[GRID_HEIGHT][GRID_WIDTH], int row, int col) {
// todo
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
bool grid[GRID_HEIGHT][GRID_WIDTH] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 1, 1, 1, 1, 1, 1, 0, 0, 0},
{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0},
{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0},
{ 0, 1, 1, 1, 0, 0, 1, 0, 0, 0},
{ 0, 0, 0, 1, 0, 0, 1, 0, 0, 0},
{ 0, 0, 0, 1, 0, 0, 1, 0, 0, 0},
{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};
printf("Before flood-filling: \n");
printGrid(grid);
floodFill(grid, 3, 3);
printf("\nAfter flood-filling: \n");
printGrid(grid);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment