Back to Practice Dashboard
Python BasicsEasy

Removing Duplicate elements from an array

Learn how to solve the 'Removing Duplicate elements from an array' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

Write a function remove_duplicates(arr) that takes a list of integers arr and returns a new list with duplicate elements removed, preserving the order of first occurrence of each element.

Constraints
  • 0 <= len(arr) <= 10^5
  • -10^6 <= arr[i] <= 10^6

Examples

Example 1
Input
arr = [1, 2, 2, 3, 4, 4, 5]
Output
[1, 2, 3, 4, 5]
Explanation

Remove the second 2 and second 4, keeping first occurrences in order.

Example 2
Input
arr = [5, 5, 5, 5]
Output
[5]
Explanation

All duplicates removed, keeping only one 5.

Example 3
Input
arr = [1, 2, 3]
Output
[1, 2, 3]
Explanation

No duplicates, array unchanged.

Need a Hint?
Use simple arithmetic operators (like modulo `%`, division `//`), conditional checks, or loops to inspect number properties.
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor