Smallest and Second-Smallest Distinct Values
Updated
Problem statement
You are given an unsorted list of integers nums. Return a list of two numbers: the smallest value in nums, and then the second-smallest distinct value.
The second-smallest distinct value is the smallest value that is strictly bigger than the smallest value. Extra copies of the smallest value do not count. For example, in [4, 1, 1] the answer is [1, 4], not [1, 1].
Function
twoSmallest(nums: int[]) → int[]Examples
Example 1
nums = [8,3,9,3,5]return = [3,5]The smallest value is 3. It appears twice, but the second copy does not count as a different value. The smallest value bigger than 3 is 5. The answer is [3,5].
Example 2
nums = [-4,10]return = [-4,10]With two different numbers, the smaller one comes first: [-4,10].
Example 3
nums = [7,7,7,2]return = [2,7]The smallest value, 2, is at the end. The only other value is 7, so the answer is [2,7].
Constraints
2 <= nums.length <= 5000-109 <= nums[i] <= 109numscontains at least two different values
More DocuSign Onsite Interview questions
- Count Binary SubstringsONSITE INTERVIEW · Seen Sep 2026
- Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Compress Consecutive Integer RangesONSITE INTERVIEW · Seen Aug 2026
- JSON Schema Object ValidatorONSITE INTERVIEW · Seen Aug 2026
- Most Transactions Kept Without Going NegativeONSITE INTERVIEW · Seen May 2025
- Three-Part Splits With a Light MiddleONSITE INTERVIEW · Seen May 2025
- Combine Two Sorted Lists Into OneONSITE INTERVIEW · Seen Apr 2022
- Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Paired Words That Share a SubstringONSITE INTERVIEW · Seen Apr 2022
- Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
Similar questions at other companies
- Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
- Longest Common PrefixKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Rotate a Matrix by 90 DegreesIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
- Plus OneDruva · ONSITE INTERVIEW
- Ring Buffer OperationsAmazon · ONSITE INTERVIEW
- Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
- Merge Sorted ArrayDP World · ONSITE INTERVIEW
- List the Key and Value of Every Map EntryNewgen Software · ONSITE INTERVIEW
- Pizza Price CalculatorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions