`{"id":"ca01f542-11c6-4c6f-8bf4-6a94e5fc5a98","name":"Counting Elements In Two Arrays","description":"Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[].\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= m,n &lt;= 10^5\r\n1 &lt;= arr1[i],arr2[j] &lt;= 10^5\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvector<int> find(vector<int> &arr1, vector<int> &arr2) {\n //write your code here\n \n }\n\nint main() {\n //input work\n int n1, n2;\n \n cin>>n1;\n vector<int> a(n1);\n for (int i = 0; i < n1; i++) {\n cin>>a[i];\n }\n\n cin>>n2;\n vector<int> b(n2);\n for (int i = 0; i < n2; i++) {\n cin>>b[i];\n }\n\n vector<int> ans = find(a, b);\n\n for (int val : ans) {\n cout<<val<<\" \";\n }\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int[] find(int[]arr1, int[]arr2) {\r\n //write your code here\r\n return null;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n\r\n int n1 = scn.nextInt();\r\n int[]a = new int[n1];\r\n\r\n for (int i = 0; i < n1; i++) {\r\n a[i] = scn.nextInt();\r\n }\r\n\r\n int n2 = scn.nextInt();\r\n int[]b = new int[n2];\r\n\r\n for (int i = 0; i < n2; i++) {\r\n b[i] = scn.nextInt();\r\n }\r\n\r\n int[]ans = find(a, b);\r\n\r\n for (int val : ans) {\r\n System.out.print(val + \" \");\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n1 2 3 4 7 9\r\n6\r\n0 1 2 1 1 4","sampleOutput":"4 5 5 6 6 6","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"7a028f6f-f04e-4f20-ad42-ea03db159567","name":"Counting Elements In Two Arrays","slug":"counting-elements-in-two-arrays","type":1}],"next":{"id":"f36d721c-bab1-4344-a7c7-6bfe54cbd11b","name":"Counting Elements In Two Arrays","type":3,"slug":"counting-elements-in-two-arrays"},"prev":{"id":"bbe7241c-6a0e-458b-b1f3-9ab8ea42d640","name":"Count Possible Triangles MCQ","type":0,"slug":"count-possible-triangles-mcq"}}}`

# Counting Elements In Two Arrays

Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[].

`{"id":"ca01f542-11c6-4c6f-8bf4-6a94e5fc5a98","name":"Counting Elements In Two Arrays","description":"Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[].\r\n","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= m,n &lt;= 10^5\r\n1 &lt;= arr1[i],arr2[j] &lt;= 10^5\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nvector<int> find(vector<int> &arr1, vector<int> &arr2) {\n //write your code here\n \n }\n\nint main() {\n //input work\n int n1, n2;\n \n cin>>n1;\n vector<int> a(n1);\n for (int i = 0; i < n1; i++) {\n cin>>a[i];\n }\n\n cin>>n2;\n vector<int> b(n2);\n for (int i = 0; i < n2; i++) {\n cin>>b[i];\n }\n\n vector<int> ans = find(a, b);\n\n for (int val : ans) {\n cout<<val<<\" \";\n }\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int[] find(int[]arr1, int[]arr2) {\r\n //write your code here\r\n return null;\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n\r\n int n1 = scn.nextInt();\r\n int[]a = new int[n1];\r\n\r\n for (int i = 0; i < n1; i++) {\r\n a[i] = scn.nextInt();\r\n }\r\n\r\n int n2 = scn.nextInt();\r\n int[]b = new int[n2];\r\n\r\n for (int i = 0; i < n2; i++) {\r\n b[i] = scn.nextInt();\r\n }\r\n\r\n int[]ans = find(a, b);\r\n\r\n for (int val : ans) {\r\n System.out.print(val + \" \");\r\n }\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"6\r\n1 2 3 4 7 9\r\n6\r\n0 1 2 1 1 4","sampleOutput":"4 5 5 6 6 6","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"7a028f6f-f04e-4f20-ad42-ea03db159567","name":"Counting Elements In Two Arrays","slug":"counting-elements-in-two-arrays","type":1}],"next":{"id":"f36d721c-bab1-4344-a7c7-6bfe54cbd11b","name":"Counting Elements In Two Arrays","type":3,"slug":"counting-elements-in-two-arrays"},"prev":{"id":"bbe7241c-6a0e-458b-b1f3-9ab8ea42d640","name":"Count Possible Triangles MCQ","type":0,"slug":"count-possible-triangles-mcq"}}}` Editor

# Counting Elements In Two Arrays

medium

Given two unsorted arrays arr1[] and arr2[]. They may contain duplicates. For each element in arr1[] count elements less than or equal to it in array arr2[].

## Constraints

1 <= m,n <= 10^5 1 <= arr1[i],arr2[j] <= 10^5

## Format

### Input

Input is managed for you

### Output

Output is managed for you

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}6 1 2 3 4 7 9 6 0 1 2 1 1 4```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}4 5 5 6 6 6`

Discussions

Show Discussion

Related Resources 