Method 1) HashMap, O(n) time and space complexity
Declare a Hash Map
where
Key ————>Number/element/data
and
Data————>Number Of occurrence
Once all the elements are processed, then display the element whose number of occurrence is 2
Method 2) Binary Tree
Declare Binary tree
Visit all the element and insert into the tree
If any of the number is already exist then display the element which is the data with number of occurrence with 2
Method 3) Maths
Traverse the list once and find the sum of all numbers and store it in a.
Calculate b = n (n-1)/2 where n=99

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