Interview Question

Interview Los Angeles, CA

First Person: Simply high level questions about how to

  achieve certain things. For example: 1) How would you write a pancake sort routine 2) You have a network of friends (linked in friends, facebook friends, etc). How would you keep track of all the people you are connected to. 3) What is the run time of the A* search (only because I mentioned it somewhere along the line). Second person: 1) Write code to find duplicates in a linked list 2) How would you synchronize a linked list across multiple computers. If nodes are added/removed to a linked list on one computer, all others must reflect this change. Concurrancy must be accounted for
Answer

Interview Answer

1 Answer

0

(duplicates in a linked list) public static ArrayList<String> dups(LL l) { ArrayList<String> dups = new ArrayList<String>(); Hashtable<String, Integer> h = new Hashtable<String, Integer>(); while (l != null) { Integer count = h.get(l.v); if (null == count) { h.set(l.v, 1); } else if (count.intValue() == 1) { h.set(l.v, 2); dups.add(l.v); } l = l.next; } return dups; }

Rahul on May 4, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.