BackmediumUncategorized uncategorized medium

Find Array Distinct Elements Solution

Problem Statement

You are given an integer array. Return a new array containing only the distinct elements from the original array in the same order they appeared.

Example 1
Input
[1, 2, 2, 3, 4, 5, 5, 6, 6]
Output
[1, 2, 3, 4, 5, 6]

Explanation: Distinct elements in the array are 1, 2, 3, 4, 5, and 6, so they are the only elements in the new array.

Constraints

  • The input array can be in any order and can contain duplicate elements.
  • The size of the input array will not exceed 10000.
  • All elements in the input array will be integers between 0 and 10000 (inclusive).
  • The input array will not be empty.
  • The distinct elements in the input array will be between 0 and 10000 (inclusive).
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free