Advertisement
satishfrontenddev5

Untitled

Feb 22nd, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must appear as many times as it shows in both arrays and you may return the result in any order.
  2.  
  3. Input format
  4. The first line contains two integers N and M, the sizes of the two arrays. The second line contains the N elements belonging to the array nums1. The third line contains the M elements belonging to the array nums2.
  5.  
  6. Output format
  7. Return the intersection of the two arrays (also include duplicates in the result).
  8.  
  9. Sample Input 1
  10. 4 2
  11.  
  12. 1 2 2 1
  13.  
  14. 2 2
  15.  
  16. Sample Output 1
  17. 2 2
  18.  
  19. Explanation
  20. The elements in [2,2] are common to both arrays.
  21.  
  22. Sample Input 2
  23. 3 5
  24.  
  25. 4 9 5
  26.  
  27. 9 4 9 8 4
  28.  
  29. Sample Output 2
  30. 4 9
  31.  
  32. Explanation
  33. [4, 9] are present in both arrays. [9, 4] will also be accepted as the answer.
  34.  
  35. Constraints
  36. 1 <= N, M <= 1000
  37.  
  38. 0 <= nums1[i], nums2[i] <= 1000
  39.  
  40.  
  41. vector<int> intersectionOfTwoArrays2(vector<int>&nums1, vector<int>&nums2){
  42.     vector<int>res;
  43.     return res;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement