Deduplicate a List While Preserving Order
Updated
Problem statement
You are given an integer array values.
Return a new array containing each distinct value exactly once. Preserve the order in which values first appear.
Function
deduplicateList(values: int[]) → int[]Examples
Example 1
values = [4,2,4,1,2,3]return = [4,2,1,3]Keep the first occurrence of each value and discard later duplicates.
Example 2
values = [-1,-1,0,-1,0]return = [-1,0]The first -1 and the first 0 determine the output order.
Example 3
values = [7]return = [7]A one-element array is already distinct.
Constraints
1 <= values.length <= 10^5.-10^9 <= values[i] <= 10^9.
More Mastercard Phone Screen questions
- Top Three Accounts by Monthly Transaction AmountPHONE SCREEN · Seen Sep 2026
- Employee With the Highest SalaryPHONE SCREEN · Seen Jul 2026
- Group Names by DepartmentPHONE SCREEN · Seen Jul 2026
- Credit and Debit Transaction Counts per UserPHONE SCREEN · Seen Apr 2026
- Users with Three Transactions in Sixty SecondsPHONE SCREEN · Seen Apr 2026
- Container With Most WaterPHONE SCREEN · Seen Oct 2025
- Employees with the Highest and Lowest SalaryPHONE SCREEN · Seen Apr 2025
- Inactive Customers with Prior ActivityPHONE SCREEN · Seen Nov 2024
- Merchant Category Transaction SummaryPHONE SCREEN · Seen Nov 2024
- Top Customers by Six-Month Transaction AmountPHONE SCREEN · Seen Nov 2024
Similar questions at other companies
- Majority ElementByteDance · PHONE SCREENByteDance interview questions
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Find Unique ElementsCisco · PHONE SCREENCisco interview questions
- Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Two SumAmazon · OA · PHONE SCREEN
- Employee Count Median, Mean and ModeClay · PHONE SCREEN
- Two SumBNSF Railway · PHONE SCREENBNSF Railway interview questions
- Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
- Cross-Day User Trust ScoresAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions