Two Smallest Values
Problem statement
Return the two smallest values in an integer array values, in nondecreasing order. Count separate occurrences of equal values separately. Return a new two-element array and leave the input unchanged.
Function
twoSmallest(values: int[]) → int[]Examples
Example 1
values = [4,2,5,1]return = [1,2]The smallest value is 1 and the next smallest occurrence is 2.
Example 2
values = [3,3,5]return = [3,3]The two occurrences of 3 are the two smallest values; distinct values are not required.
Example 3
values = [7,-2]return = [-2,7]With two input values, return them in nondecreasing order.
Constraints
2 <= values.length <= 10000.-2147483648 <= values[i] <= 2147483647.