Problem Solving: Write code to remove duplicates from an unsorted linked list.

Problem

Write code to remove duplicates from an unsorted linked list.

Solution

Two types of solution came to my mind 1) Use hashmap to check the duplicates and remove that as necessary. Time complexity for this solution is O(n) and Space Complexity O(n) 2) We also can check if by checking all previous entries for duplciate. In this case time complexity will be O(n^2) and Space Complexity O(1)

Code

Comments

Popular posts from this blog

Scala Learning: Finding Square Root

Deleting a hidden user in MAC

Problem Solving: Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node