This is my O(n) solution. We don't need to parse any of the strings to an integer.
constfindIntersection=(arr)=>{// n1 - larger array// n2 - smaller arrayletn1,n2;if(arr[0].split(',').length>arr[1].split(',').length){n1=arr[0].split(',');n2=arr[1].split(',');}else{n1=arr[1].split(',');n2=arr[0].split(',');}letlen=n1.length;// store the common itemsletcommon=[];for(leti=0;i<len;i++){// check if an item of one array (larger one) exists in the other array (smaller one)if(n2.includes(n1[i])){common.push(n1[i]);}}returncommon.length?common.join():"false";}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is my O(n) solution. We don't need to parse any of the strings to an integer.