Array ( [0] => [1] => questions [2] => Arrays [3] => Removing-Duplicates )
Given list of elements. You have to remove the duplicate elements in given array and print the array.
First line contains a number N. Next line contains N integers separated by spaces.
Print the resultant array.
5 3 5 4 4 1
3 5 4 1
8 2 5 4 3 4 1 2 7
2 5 4 3 1 7
10 9 3 8 4 7 5 9 2 3 8
9 3 8 4 7 5 2
Login to see Discussion
Approach 1: using Brute Force
Step-i) create a temp array of the given array size
Step-ii) initialize all the values with true
Step-iii) run a loop from i=0 to i
Step-v) run a loop from j=i+1 to j
Step-vii) create an empty string
Step-viii) run a loop form i = 0 to i
Step-x) return the string
Time Complexity: O(n^2)
Space Complexity: O(n)
Approach 2: using set data structure
Step-i)create a empty set
Step-ii) add all elements of array to the set
Step-iii) now you can either return the set or create an empty string and add set elements to it and return it as done below in
the given example
Time Complexity: O(n)
Space Complexity: O(n)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution