Can YOU Improve The Solution?? - Leetcode 349 - Intersection of Two Arrays

preview_player
Показать описание
Can YOU Improve The Solution?? - Leetcode 349 - Intersection of Two Arrays #FAANG #datastructuresandalgorithms #programming #softwareengineering #codinginterview #softwaredevelopment #software #softwaredeveloper #softwarejobs #softwareengineer #datastructures #leetcode #codingisfun #code #coding #javascript #javascriptdeveloper #js
Рекомендации по теме
Комментарии
Автор

I can't express how much I love these intros.

dsp
Автор

You can do that in 2 ways
Way 1 instead of creating both array as set convert 1 array which is smaller to set and just linearly traverse the entire array 2 and see its value in the set and which match append it to result
First approch reduce space complexity

Second way can be sort one array and then you can again linearly traverse on second array and use binary search to find it in sorted if found append to the result


This will not required any extra space but need more time o(n log n)

abdulsaboor
Автор

You don’t need to convert both arrays to sets. Just convert one and iterate over another array + make result a set

silentroach
Автор

Single line in python

list(set(n1)& set(n2)) 😂

ShardulPrabhu
Автор

can you merge them and find duplicates?

amoljoshi
Автор

First sort them. Then Iterate through a till the end of small array and and the elements to list

sumanthuh