Method 1) Using extra space
Bucket sort if range is known
Declare an array of known range and initialize the value of each element as zero
On visiting each input number increment the corresponding array by 1(e.g. if 2 is found then make a[2]+=1)
At the last visit all the elements in the array and display the element if the array value is non-zero. This way the repeated number will be removed
Method 2) without extra space
Sort the elements
Keep info about the first element that is visited and the first array that has been filled
Once the info element is not equal to next element (means non-duplicate), put that next to the array that has been filled up
the problem to find duplicate and remove duplicate character to get code/algorithm

Leave a Reply
You must be logged in to post a comment.