Problem · Sorting

Find Unique Values

Learn this problem
EasyAmazonFULLTIMEOA
See Amazon hiring insights

Problem statement

There are n developers working at Amazon where the ith developer has the experience points experience[i]. The company decided to pair the developers by iteratively pairing the developers with the highest and lowest remaining experience points for a hackathon. The combined experience of a pair is the average of the experience points of the two developers. Find the number of unique values among the combined experience of the pairs formed.

Function

findUniqueValues(experience: int[]) → int

Complete the function findUniqueValues in the editor below.

findUniqueValues has the following parameter:

  1. int experience[n]: the experience points for each developer

Returns

int: the number of unique values among the combined experience points of the pairs formed

Examples

Example 1

experience = [1, 4, 1, 3, 5, 6]return = 2
There are n = 6 developers. The pairs formed are (1, 6), (1, 5), and (4, 3) making their experience points 3.5, 3, and 3.5 respectively. There are 2 distinct values, 3 and 3.5, so return 2 as the answer.

Example 2

experience = [1, 1, 1, 1, 1, 1]return = 1
The developers will be paired up as follows (by index): (0, 1), (2, 3), and (4, 5). Each pair has a combined experience of 1.

Example 3

experience = [1, 100, 10, 1000]return = 2
The developers are paired as follows (by index): (0, 3), (1, 2). The pairs have combined experience points of 500.5, and 55 respectively.

Constraints

  • 1 <= n <= 105
  • n is an even number
  • 1 <= esperience[i] <= 109
  • More Amazon problems

    drafts saved locally
    public int findUniqueValues(int[] experience) {
        // write your code here
    }
    
    experience[1, 4, 1, 3, 5, 6]
    expected2
    checking account