Print unique elements of the array in the same order as they appear in the input. Using Python
Posted on | Sunday, 14 May 2023 | No Comments
Print unique elements of the array in the same order as they appear in the input.
Note: Do not use any inbuilt functions/libraries for your main logic.
Input Format
First line of input contains a single integer N - the size of array and second line contains array elements.
Constraints
1 <= N <= 100
0 <= ar[i] <= 109
Output Format
Print unique elements of the array.
Sample Input 0
7
5 4 10 9 21 4 10
Sample Output 0
5 9 21
k=int(input())
b=[]
a=list(map(int,input().split()))
for i in range(k):
for j in range(k):
if a[j]==a[i] and j!=i:
b.append(a[i])
r = [i for i in a if i not in b]
for i in range(len(r)):
print(r[i],end=" ")

Comments
Categories
Archives
- May 2023 (30)
Leave a Reply