Given two unsorted arrays arr1[] and arr2[], which may contain duplicates, count the number of elements in arr2 that are less than or equal to each element in arr1.
Input: arr1 =[4,2,8], arr2 =[5,1,3,7,9,2]Output: [3,2,5]Explanation:
For arr1[0]=4, there are 3 elements in arr2 less than or equal to 4(i.e.,1,3,2).For arr1[1]=2, there are 2 elements in arr2 less than or equal to 2(i.e.,1,2).For arr1[2]=8, there are 5 elements in arr2 less than or equal to 8(i.e.,5,1,3,7,2).
Example 2:
1
2
3
4
5
Input: arr1 =[10,5], arr2 =[6,3,8,10,15]Output: [4,2]Explanation:
For arr1[0]=10, there are 4 elements in arr2 less than or equal to 10(i.e.,6,3,8,10).For arr1[1]=5, there are 2 elements in arr2 less than or equal to 5(i.e.,3,5).
Utilize two nested loops: the outer loop iterates over the elements of arr1[] and the inner loop iterates over the elements of arr2[]. For each element in arr1[], count the number of elements in arr2[] that are less than or equal to it. The time complexity of this approach is (O(m * n)), where arr1[] and arr2[] have sizes m and n, respectively.