FastPrepTwo Smallest Values
Problems/Two Smallest Values

Two Smallest Values

Xilinx logoXilinx● EasyNEW GRADONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the two smallest array values without specifying duplicate handling, bounds or interface. This exercise counts duplicate occurrences, returns the pair in sorted order and leaves the input unchanged. Approximate source match: 80%.

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.

More Xilinx problems

  • Count Ones in a 16-bit WordONSITE INTERVIEW · Seen Feb 2019
  • Delete a Given Linked-list NodeONSITE INTERVIEW · Seen Feb 2019
  • Reservation-station Tag MatchONSITE INTERVIEW · Seen Feb 2019
All Xilinx interview questionsSee Xilinx hiring insights
Saved
public int[] twoSmallest(int[] values) {
    return new int[0];
}
Checking account…