ProgrammingHard
Count the 4-connected islands of 1s in this grid, where rows are "11000", "11010", "00100", "00011". How many islands are there?
- A. 2
- B. 3
- C. 5
- D. 4
Correct answer: D. 4
The islands are the top-left 2 x 2 block, the lone 1 in row 1, the lone 1 in row 2, and the pair at the bottom right. Diagonal neighbours do not connect, so the lone cells stay separate.
More C Programming questions
- In Pascal's triangle with row 0 at the top, what is the entry in row 6, column 2?
- The matrix [[1,1],[1,0]] raised to the 10th power, computed by fast exponentiation, has entry [0][1] equal to which Fibonacci number?
- Which prototype is valid in C99 for a function that takes a column count c and an int matrix m with c columns?
- For int a[1000][1000], which loop walks memory in address order (the cache-friendly order)?
- Which declaration makes a 10^6 int matrix at run time without depending on the stack size?
- For a matrix of size n x n with n = 500, which algorithm is correct and fast enough within 1 second for C multiplication?