Find the Duplicate Values
Updated
Problem statement
You are given an integer array nums of length n. Every value in nums is between 1 and n, and no value appears more than twice.
Return every value that appears twice in nums, in increasing order. If no value appears twice, return an empty list.
Function
findDuplicates(nums: int[]) → List<Integer>Examples
Example 1
nums = [5,1,5,2,6,1]return = [1,5]Here n = 6. The value 5 is at indices 0 and 2, and the value 1 is at indices 1 and 5. The values 2 and 6 appear once, and 3 and 4 do not appear. In increasing order the answer is [1,5].
Example 2
nums = [3,1,2]return = []Each of 1, 2 and 3 appears exactly once, so no value appears twice and the answer is an empty list.
Example 3
nums = [4,4,3,3]return = [3,4]Both 4 and 3 appear twice. The pair of 4s comes first in the array, but the answer lists the values in increasing order, so it is [3,4].
Constraints
n == nums.length1 <= n <= 5 * 1041 <= nums[i] <= n- Each value appears in
numsat most twice.
More Airbnb Phone Screen questions
- Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
- Text JustificationPHONE SCREEN · Seen Nov 2026
- Decode and Store StringsPHONE SCREEN · Seen Oct 2026
- Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
- Smallest Common RegionPHONE SCREEN · Seen Aug 2026
- Longest Chain BookingPHONE SCREEN · Seen Aug 2026
- Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
- Parse Query StringPHONE SCREEN · Seen May 2026
- Pacific Atlantic Water FlowPHONE SCREEN · Seen May 2023
Similar questions at other companies
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsStripe · PHONE SCREENStripe interview questions
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN
- Insert Delete GetRandom O(1)Charta Health · PHONE SCREENCharta Health interview questions
- Longest Consecutive SequenceKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
- Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Top K Frequent Elements with a Recency TiebreakSwiggy · PHONE SCREEN
Interview reports that mention this question
Airbnb interview experiences
- Airbnb SWE OA: Four-Level Banking System: 1 Experience
- Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
- Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
- Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
- Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)