Intersection of Two Arrays
Convert both arrays to sets, intersect them, and sort the result if you want deterministic output for testing or interviews.
Return the unique values that appear in both arrays.
Tagged with set
Convert both arrays to sets, intersect them, and sort the result if you want deterministic output for testing or interviews.
Return the unique values that appear in both arrays.
Put all numbers in a set, then expand sequences only from values whose previous number is absent. That avoids re-counting the same streak multiple times.
Return the length of the longest consecutive sequence in an unsorted array.
Convert both arrays to sets, take the union, and sort the result if stable output is helpful.
Return the unique values that appear in either array.