C and Java solutions are in space O(n*m). it's possible to do this in space O(min


#1

C and Java solutions are in space O(nm). it’s possible to do this in space O(min(n,m)) (specifically 2min(n,m)).


#2

Also possible in constant space by modifying the input array.