Remove Duplicates While Preserving Order
Updated
Problem statement
You are given an integer array nums. Return an array containing each distinct value exactly once, in the order of its first occurrence in nums.
The input is not necessarily sorted. Return an empty array when nums is empty.
Function
removeDuplicates(nums: int[]) → int[]Examples
Example 1
nums = [1,2,2,4,4]return = [1,2,4]The first occurrences of 1, 2, and 4 are at indices 0, 1, and 3, respectively.
Example 2
nums = [5,4,1,5]return = [5,4,1]Keep the first 5, then 4 and 1. Ignore the final 5 because that value has already appeared.
Example 3
nums = [5,2,5,1]return = [5,2,1]Keep 5 and 2, skip the repeated 5, and then keep 1.
Constraints
0 <= nums.length <= 100000-10^9 <= nums[i] <= 10^9
More Akuna Capital Phone Screen questions
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Sep 2026
- Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
- Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
- Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
- Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
- Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025
- Reverse Nodes in Groups of KPHONE SCREEN · Seen Oct 2025
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
- List the Key and Value of Every Map EntryNewgen Software · ONSITE INTERVIEW
- Pizza Price CalculatorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions