How will you check to see if two integer arrays have any common elements?
Anonymous
Soln1: 1) Sort array1 and array2 2) Follow the implementation by @solutionYoda. Soln2: 1) Store the array1 value in hashmap 2) Iterate the array2 and check if the element is existing in hashmap. If yes then print the value. or you can change the value of the map.put(key,"true"). Time complexity O(m) for array1 to put in hashmap O(n) for array2 and check it in hashmap. plus some operation to change the value for matched value. Space Complexity O(m) for the array1. Always choose smaller array to store the value in hashmap.
Check out your Company Bowl for anonymous work chats.