Alin
BAN USER
Comments (3)
Reputation 40
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote
What if we used another file and a hash map? For each line read from the original file, hash it and check if it exists in the hash map and if it does it means that it's a duplicate so you just don't write it in the new file. This would require only one pass but it also requires doubling the storage space and the extra memory for the hash map.
- Alin January 31, 2014Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Solving this in O(n) time and O(1) space seems impossible and I could only come up with a 'workaround' that involves using a recurrent algorithm so I could rely on the stack to hold the odd values. When the recursion returns, I just simply fill the array with the odd values from the stack.
- Alin February 01, 2014