I am dealing with a problem of problematic complexity through my university:
Program input: A nxn Array[][] , which is populated with either 0 or 1 .
DEFINITION: Define k as SINK if the row k all the values 0 and the column k all the values 1 (except [k][k] , which should be 0 )
Program output: is there a number k that is SINK ? If yes, return k , else return -1 .
Example:

On Arr A k = 3 is SINK, on ββArr B there is no SINK, so -1 is returned.
The main problem with this task is that the complexity of the program should be lower than O(n^2) , I managed to solve this problem with such complexity by going along an inclined line, summing the columns of rows and columns. I did not find a way to solve this problem using O(logn) or O(n) . Also, the task does not allow the use of another array [] (due to memory complexity). Can anyone highlight this issue? thanks in advance!
java arrays c # algorithm task
Oran ge
source share