• + 9 comments

    I think you mis-understood how this piece of the code works

    for(int i = 0, j = 0; i < n; i++)
    	for(; j < m; j++)
    

    This is a n+m for loop iterator, notice how m is not reset after each loop of n. So I don't check every pairing but rather only the pairings that make logical sense. Also the O(n log(n)) time I state as the upper bound is where n = n+m, but I am guessing you already knew that.