FastPrepSmallest and Second-Smallest Distinct Values
Problems/Smallest and Second-Smallest Distinct Values

Smallest and Second-Smallest Distinct Values

DocuSign logoDocuSign● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report from February 2020 lists this as the first technical session of a three-part onsite. The task is to find the two smallest elements of an unsorted array.

The report gives no limits or examples. It does not say how repeated values count or what form the answer takes. Here copies of the smallest value do not count, so the second answer is the next bigger value. Every list has at least two different values. You return both numbers as a two-item list, smallest first. The list has 2 to 5,000 integers between -10^9 and 10^9. We wrote the examples.

Our version is about 85% the same as the reported question.

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] <= 109
  • nums contains 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

Interview reports that mention this question

  • DocuSign SWE Intern Interviews: 27 Experiences (Part 2 of 2)

DocuSign interview experiences

  • DocuSign SWE Intern OA Questions: 53 Experiences (Part 1 of 2)
All DocuSign interview questionsSee DocuSign hiring insights
Saved
class Solution {
    public int[] twoSmallest(int[] nums) {
        // Write your code here.
    }
}
Checking account…