Goldman Sachs

www.goldmansachs.com

Interview Question

Summer Analyst Interview

Write a function that accepts two arrays and returns one

  array with the elements in a but not in b?
Answer

Interview Answer

2 Answers

0

Make a new array c
Make a bool duplicate = false
Loop through a
For each element in a, loop through b
if a=b, change duplicate to true,
Now when you are done with your inner b loop
perform an if condition check on the bool
If duplicate = false, then current element in a you are looping over into array c

Anonymous on Nov 8, 2013
0

^ for the above solution: this new array c should be initiliazed to have the same size as a.
In the case there are elements in a that are also in b, c would have indices where there is no element in a particular index

Anonymous on Nov 8, 2013

Add Answers or Comments

To comment on this, Sign In or Sign Up.