您可以以O(nlogn)复杂度执行上述算法,其中n是问题中给出的数组A和数组B的长度。
算法
1. Sort both the arrays A and B, this will take O(nlogn) time complexity.2. Take two pointers i and j, initialize both of them to 0. we will use i for array A and j for B.3. Create a result array res of size n.4. Start a while loop while(i<n && j<n) { if(A[i] > B[j]) { j++; } else { res[i] = j+1; i++; } }5. while(i<n) { res[i] = n; } This step is for the case where all elements in A are bigger than all elements in B.最后,您将获得
res答案的数组。
总时间复杂度-
O(nlogn)。
希望这可以帮助!



