I think the expected answer of first additional example should be 3 and for third it should be 1. Here is why. I have shown the holes with indices (0-based indexing is used).
matrix_first = [ "01111" "01101" "00011" "11110" ] First Hole : (0, 0), (1, 0), (2, 0), (2, 1), (2, 2) Second Hole : (1, 3) Third Hole : (3, 4)
matrix_second = [ "110", "000", "111" ] First and Only Hole : (0, 2), (1, 2), (1, 1), (1, 0)
We need to keep in mind that,
A contiguous region is one where there is a connected group of 0's going in one or more of four directions: up, down, left, or right.
This is why for the first case (1, 3) is a separate hole.
(1, 3)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think the expected answer of first additional example should be 3 and for third it should be 1.
Here is why.
I have shown the holes with indices (0-based indexing is used).
We need to keep in mind that,
This is why for the first case
(1, 3)
is a separate hole.