I am working on one programming challenge in which I have to find number of zeros surrounded by ones.
I have given:
Number of row and columns r and c
Number of positions of ones n
n positions i j where i is index of row and j is index of column
For example if I have
011110 010001 010001 001110 000000
then I return 6.
There are 3 test input sets. In the first two sets r, c <= 1000. I managed to pass the first two sets by using DFS to cout number of zeros which are not surrounded by ones (starting from borders). Hence number of zeros z = r * c - k - n where k is number of zeros which are not surrounded by ones.
But in the third case r, c <= 10^18 which doesn't even fit to memory if I create two dimensional vector on beginning. I also noticed that n is relative small in all sets (n <= 10^6).
My question is how to solve this problem for all test sets?