It will be better if we allow invalid inputs, and output -1.


  • -1
    M

    Otherwise this question is too easy, just equivalent to finding the number of islands since we know we are always having a valid input.


  • 1
    B

    The challenge is to do it with O(1) space, and in one pass.
    Not saying this is a hard question - but the number of islands solution is not a good solution for this question.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.