Hi , obviously this problem can be solved in O(N*M) with help of an array for counting, because numbers are <=1000 . but what is the best algorithm for solving this problem when numbers are <=1e9 ?
I wrote this code that works in O( N*M*log(N*M) ) but it got TimeLimit ( in 1second ) . How can we reduce this complexity ?
UPD : sorry , I linked to wrong source code. fixed.