FastPrepDistinct Duplicate Values

Distinct Duplicate Values

Lloyds Banking Group logoLloyds Banking Group● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Given an integer array data, return every distinct value that appears at least twice.

Return each duplicate value exactly once, ordered by the position of its first occurrence in data. If no value is duplicated, return an empty array.

Function

findDuplicateValues(data: int[]) → int[]

Examples

Example 1

data = [4,2,4,3,2,4]return = [4,2]

Values 4 and 2 both occur more than once. The first 4 appears before the first 2.

Example 2

data = [1,2,3,4]return = []

Every value appears exactly once.

Example 3

data = [7,7,7,7]return = [7]

The repeated value is returned only once regardless of how many times it appears.

Constraints

  • 1 <= data.length <= 100000.
  • -10^9 <= data[i] <= 10^9.

Source note: Author-written prompt excerpt retained for source fidelity.

See Lloyds Banking Group hiring insights
public int[] findDuplicateValues(int[] data) {
    // Write your code here.
}
data[4,2,4,3,2,4]
expected[4,2]
Checking account…