write a program to remove duplicate elements in an array
sample input:
5
1 3 4 3 4
sample output
1 3 4
Answers
Answered by
0
Answer:
For example, consider the array
case 1: Remove duplicates from sorted array
Input: arr = {1, 2, 3, 4, 4}
Output: arr = {1, 2, 3, 4}
case 2: Remove duplicates from unsorted array
Input: arr = {9, 2, 7, 4, 7}
Output: arr = {9, 2, 7, 4}
Algorithm to remove duplicate elements in an array (sorted array)
Input the number of elements of the array.
Input the array elements.
Repeat from i = 1 to n
- if (arr[i] != arr[i+1])
- temp[j++] = arr[i]
- temp[j++] = arr[n-1]
Repeat from i = 1 to j
- arr[i] = temp[i]
return j.
Similar questions