Given two arrays
a[] = {1,3,2,4}
b[] = {4,2,3,1}
both will have the same numbers but in different order. We have to sort both of them. The condition is that you cannot compare elements within the same array.
Given two arrays
a[] = {1,3,2,4}
b[] = {4,2,3,1}
both will have the same numbers but in different order. We have to sort both of them. The condition is that you cannot compare elements within the same array.
I can give you an algorithm of O(N*log(N)) time complexity based on quick sort.
Time complexity: T(N) = 2*T(N/2) + O(N). So the overall complexity is O(N*log(N)) according to master theorem.
Not sure I understood the question properly, but from my understanding the task is a follows:
Sort a given array
awithout comparing any two elements fromadirectly. However we are given a second arraybwhich is guaranteed to contain the same elements asabut in arbitrary order. You are not allowed to modifyb(otherwise just sortband return it...).
In case the elements in a are distinct this is easy: for every element in a count how many elements in b are smaller. This number gives us the (zero based) index in a sorted order.
The case where elements are not necessarily distinct is left to the reader :)