From dede649a1c60cbb343b869689e72efb0c2cfbeb0 Mon Sep 17 00:00:00 2001 From: Aviral Pratap Singh Date: Sat, 4 Oct 2025 22:59:41 +0530 Subject: [PATCH] Create remove_duplicate.py created a program to remove duplicate values from a given sorted array --- data_structures/arrays/remove_duplicate.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 data_structures/arrays/remove_duplicate.py diff --git a/data_structures/arrays/remove_duplicate.py b/data_structures/arrays/remove_duplicate.py new file mode 100644 index 000000000000..2bc67d7bc5a9 --- /dev/null +++ b/data_structures/arrays/remove_duplicate.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)