Intersection of Two Lists
Updated
Problem statement
Given two integer lists listA and listB, return their set intersection: every distinct integer that occurs in both inputs.
Each common value must appear exactly once in the result. Return the values in increasing order so that the output is deterministic.
Function
intersectLists(listA: int[], listB: int[]) → int[]Examples
Example 1
listA = [1,2,2,1]listB = [2,2]return = [2]The only distinct value present in both lists is 2.
Example 2
listA = [4,9,5]listB = [9,4,9,8,4]return = [4,9]4 and 9 occur in both inputs and are returned once each in increasing order.
Example 3
listA = []listB = [1,2,3]return = []An empty list has no values in common with the other list.
Constraints
0 <= listA.length, listB.length <= 200000-10^9 <= listA[i], listB[i] <= 10^9- The returned values must be unique and sorted in increasing order.
More LinkedIn Phone Screen questions
- Total Years of Work ExperiencePHONE SCREEN · Seen Nov 2026
- Sum an Arbitrary-Dimensional ArrayPHONE SCREEN · Seen Oct 2026
- Known Words Matching Phone DigitsPHONE SCREEN · Seen Oct 2026
- Inverse-Depth Nested List SumPHONE SCREEN · Seen Oct 2026
- Valid Number with ExponentsPHONE SCREEN · Seen Oct 2026
- Maximum Product of a Contiguous SubarrayPHONE SCREEN · Seen Oct 2026
- Maximum Sum of a Contiguous SubarrayPHONE SCREEN · Seen Oct 2026
- Sort a Quadratic-Transformed ArrayPHONE SCREEN · Seen Oct 2026
- Constant-Time Minimum StackPHONE SCREEN · Seen Oct 2026
- Randomized String MultisetPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
- Values Exclusive to the Current UserMeta · PHONE SCREENMeta interview questions
- Count Values Appearing Exactly OnceAgoda · PHONE SCREENAgoda interview questions
- Top Two Users by Total Purchase AmountSnowflake · PHONE SCREENSnowflake interview questions
- Restaurant Vote LeadersZipRecruiter · PHONE SCREEN · ONSITE INTERVIEWZipRecruiter interview questions
- AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions