FastPrepFastPrep
Problem Brief

Find Unique Values

FULLTIMEOA
See Amazon online assessment and hiring insights

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 Description

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

1Example 1

Input
experience = [1, 4, 1, 3, 5, 6]
Output
2
Explanation
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.

2Example 2

Input
experience = [1, 1, 1, 1, 1, 1]
Output
1
Explanation
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.

3Example 3

Input
experience = [1, 100, 10, 1000]
Output
2
Explanation
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

Limits and guarantees your solution can rely on.

  • 1 <= n <= 105
  • n is an even number
  • 1 <= esperience[i] <= 109
  • public int findUniqueValues(int[] experience) {
        // write your code here
    }
    
    Input

    experience

    [1, 4, 1, 3, 5, 6]

    Output

    2

    Sign in to submit your solution.

    Company OA Practice

    Find Unique Values for Amazon online assessment prep

    FastPrep catalogs Find Unique Values as a Amazon coding interview and online assessment practice problem. Review the prompt, examples, constraints, and nearby company problems together so the preparation context stays focused on Amazon OA patterns.