From f7c1f62f13551d9568fb5dd85ae353dcdb659e36 Mon Sep 17 00:00:00 2001 From: Aviral Pratap Singh Date: Sat, 4 Oct 2025 23:31:00 +0530 Subject: [PATCH] Create remove_duplicates_fromarray.py program to remove duplicates from a array --- .../arrays/remove_duplicates_fromarray.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 data_structures/arrays/remove_duplicates_fromarray.py diff --git a/data_structures/arrays/remove_duplicates_fromarray.py b/data_structures/arrays/remove_duplicates_fromarray.py new file mode 100644 index 000000000000..2bc67d7bc5a9 --- /dev/null +++ b/data_structures/arrays/remove_duplicates_fromarray.py @@ -0,0 +1,17 @@ +# Program to remove duplicates from a sorted array + +# Input: sorted array +arr = [1, 1, 2, 2, 3, 4, 4, 5] + +print("Original array:", arr) + +# Create an empty list to store unique elements +unique_arr = [] + +# Traverse the array +for num in arr: + # Add the number only if it's not already in unique_arr + if len(unique_arr) == 0 or num != unique_arr[-1]: + unique_arr.append(num) + +print("Array after removing duplicates:", unique_arr)