Find All Repeated Numbers
Updated
Problem statement
You are given an integer array nums of length n. Every value in nums is between 0 and n - 1, inclusive. A value can appear any number of times, and several different values can repeat.
Return every value that appears at least twice in nums. List each such value once, in increasing order. If no value repeats, return an empty array.
Goal: aim for O(n) time and O(1) extra space, not counting the returned array. You may change nums while you work. The judge checks only the returned array; it does not measure the extra space you use.
Function
findRepeatedNumbers(nums: int[]) → int[]Examples
Example 1
nums = [3,1,4,1,5,0,3,1]return = [1,3]Here n = 8, so every value is between 0 and 7. The value 1 appears three times and 3 appears twice. The values 0, 4 and 5 appear once, and 2, 6 and 7 do not appear. Each repeated value is listed once, from smallest to largest: [1,3].
Example 2
nums = [2,0,1,3]return = []Every value from 0 to 3 appears exactly once, so no value repeats and the answer is an empty array.
Example 3
nums = [4,0,4,0,2]return = [0,4]The value 4 appears first at index 0 and again at index 2, and 0 appears at indices 1 and 3. Both repeat. The answer lists them in increasing order, [0,4], even though the second 4 comes before the second 0.
Constraints
1 <= n == nums.length <= 10^50 <= nums[i] <= n - 1
More Nutanix Onsite Interview questions
- Design Hit CounterONSITE INTERVIEW · Seen Oct 2026
- Peak Process MemoryONSITE INTERVIEW · Seen Aug 2026
- Minimum Operations to Transform ArrayONSITE INTERVIEW · Seen Jun 2026
- Count Connected Components in an Undirected GraphONSITE INTERVIEW · Seen Aug 2025
- LRU CacheONSITE INTERVIEW · Seen Aug 2025
- Running Median of a Multilevel Linked List in Level OrderONSITE INTERVIEW · Seen Aug 2025
- Custom Array IteratorONSITE INTERVIEW · Seen Dec 2024
- Collapse Runs of Repeated CharactersONSITE INTERVIEW · Seen Nov 2022
- Anagram Words in a SentenceONSITE INTERVIEW · Seen Apr 2022
- Sudoku SolverONSITE INTERVIEW · Seen Feb 2022
Similar questions at other companies
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
- Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
- Count Subarrays with Equal Even and Odd CountsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Instant-Runoff Voting WinnerWise · ONSITE INTERVIEW
- Sudoku Board ValidationConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Indexed Person Record QueriesGoogle · ONSITE INTERVIEWGoogle interview questions