C# Improved algorithm

Posted by generixs on Stack Overflow See other posts from Stack Overflow or by generixs
Published on 2009-11-18T19:17:57Z Indexed on 2010/03/11 20:29 UTC
Read the original article Hit count: 108

Filed under:
|
|

I have been asked at interview (C# 3.0) to provide a logic to remove a list of items from a list.

I responded

int[] items={1,2,3,4}; 
List<int> newList = new List<int>() { 1, 2, 3, 4, 5, 56, 788, 9 };
newList.RemoveAll((int i) => { return items.Contains(i); });

1) The interviewer replied that the algorithm i had employed will gradually take time if the items grow and asked me to give even better and faster one.What would be the efficient algorithm ?

2) How can i achieve the same using LINQ?

3) He asked me to provide an example for Two-Way-Closure? (General I am aware of closure, what is Two-Way-Closure?, I replied there is no such term exists,but he did not satisfy).

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics