Bloomberg L.P.

  www.bloomberg.com
  www.bloomberg.com

Interview Question

Software Engineer Interview

2 lists, find the common elements amongst the list. Do it

  w/ and w/o external storage, as fast as possible.
Answer

Interview Answer

2 Answers

0

1) With external storage
Using two stacks to push all elements into them. Then pop until get different elements;

2) Without external storage
Calculate the length of two lists, l1 and l2, using two pointers which p2 is l2 - l1 steps ahead p1(suppose l2 > l1). Walk through list until find same element.

Anonymous on Apr 10, 2013
0

in python:
 r=[x for x in l1 if x in l2]

Anonymous on Feb 1, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.