Brute Force Approach:
To identify and eliminate duplicates simultaneously, we may generate a new array that is the exact length of the original array and compare each element to its neighbor. In the case of a successful comparison, we would transfer one instance of the matching value from the original to the new array.
Solution Steps:
- Return the array by checking if the array's length is
0
or1
. - Declare a variable
temp
to store the single instance of each element. - The input array will be scanned and copied a single instance of each element from
arr
totemp
. - The variable
p
will be tracking the count of the single instance of each element. - We will copy each element's single instance from
temp
toarr
. - And last, we will return the length of the array and the resultant
arr
by eliminating the duplicated element.

Here's to reference code for a better understanding!
1def RemoveDuplicates(arr, N):
2 if N == 0 or N == 1:
3 return N
4
5 temp = list(range(N))
6 p = 0;
7
8 for i in range(0, N-1):
9
10 if arr[i] != arr[i+1]:
11 temp[p] = arr[i]
12 p += 1
13
14 temp[p] = arr[N-1]
15 p += 1
16
17 for i in range(0, p):
18 arr[i] = temp[i]
19
20 return p
21
22arr = [2,3,4,4,5,6,6,6,7,8,8]
23a = len(arr)
24
25a = RemoveDuplicates(arr, a)
26print(a)
27lst =[]
28lst =[0 for i in range(a)]
29for i in range(a):
30 lst[i] = arr[i]
31print(lst)