1122. Relative Sort Array

there is a constrait : 0 <= arr1[i], arr2[i] <= 1000 .=> so we can use idea like couting sort
time: O(m+n)
space: O(1), in-place
use treemap
follow-up:
What if this constraint 0 <= arr1[i], arr2[i] <= 1000 doesn't exist?
0 <= arr1[i], arr2[i] <= 1000 doesn't exist?time: O(nLogn)
space: O(n)
my origin idea:
time: O(nLogn)
space: O(n)
Last updated
Was this helpful?