Interview Question

Interview Seattle, WA

Given an array of integers, how would you move the

  duplicate integers into a different array? What is the efficiency of your algorithm?

Interview Answer

1 Answer


In Java I'd do this using a hashset and newly created array(of dups). Simply iterate over the array checking first to see if the value already existed in the hashset. If it already exists add to array(of dups) if not add to hashset.

Action on Feb 25, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.