FastPrepRemove Duplicates While Preserving Order

Remove Duplicates While Preserving Order

Wells Fargo logoWells Fargo● EasyFULLTIMEOA
Learn

Problem statement

You are given an integer array values.

Remove duplicate occurrences so that each distinct value appears exactly once. Preserve the order of first appearance.

Return the resulting array.

Function

removeDuplicatesPreservingOrder(values: int[]) → int[]

Examples

Example 1

values = [1,1,3,2,1,4,5,4]return = [1,3,2,4,5]

Keep the first occurrences of 1, 3, 2, 4, and 5 in their original order.

Example 2

values = [1,2,3]return = [1,2,3]

Every value is already distinct.

Example 3

values = [-1,-1,0,-1]return = [-1,0]

Keep the first -1 and the first 0.

Constraints

  • 1 <= values.length <= 10^5.
  • -10^6 <= values[i] <= 10^6.

More Wells Fargo problems

See Wells Fargo hiring insights
public int[] removeDuplicatesPreservingOrder(int[] values) {
  // write your code here
}
values[1,1,3,2,1,4,5,4]
expected[1,3,2,4,5]
Checking account…