Interview Question
Country: United States
IF EXTRA SPACE is ALLOWED
use hashSet in java .
1. create a new hashSet HS
2. for every element in the array, check if hashSet contains the element (using HS.contains(element)) .
if the method returns False , then add the element in the hashSet .
3. Traverse next element in arrray and repeat step 2.
Space Complexity: O(n)
Time Complexity: O(n)
- Satveer Singh June 05, 2014