I'm dealing with some problematic complexity question via my university:
Program input : A n x n
Array[][]
that is filled with either 0
or 1
.
DEFINITION: Define k
as a SINK if in the k
row all the values are 0
, and in the k
column all the values are 1
(except [k][k]
itself which needs to be 0
)
Program output : Is there a k number that is a SINK? If so, returnk
, else return -1
.
Example :
On Arr A k=3 is a SINK, on Arr B there in no SINK, so -1 is returned.
The main problem with this task is that the complexity of the program must be below O(n^2)
, I have managed to solve this with that complexity, going over the oblique line summing the rows&columns. I haven't find a way to solve this with O(logn)
or O(n)
. Also the task prevents you from using another Array[] (Due to memory complexity). Can anyone drop any light on that matter? thanks in advance!