Great Interview Question
I'm constantly on the look up for good questions to ask in interviews, mainly because "describe the page life-cycle" gets boring and I would like to get away from the page lifecycle myself. The problem with finding good questions is that it has to expose as much knowledge from the candidate, while keeping the answer short and possible to answer within the time limits of an interview.
Here is one that I just thought of:
Basically, build a set class. This is a good question in my opinion because it tests a wide range of knowledge, in a short question, which can be implemented in about 10 minutes. The question test the following:
- Basic data structure / efficencies knowledge - if they decide to use ArrayList and compare each time, that would cost in both time to develop and performance
- Thinking toward reuse - if they implement this from scratch (starting from building growable arrays and moving forward), that means that they either have a problem with knowing the building blocks of the framework or they suffer from NIH.
- Understanding basic idioms of the framework - implementing IEnumerable will make the collection usable for foreach(), for instnace.
- Understanding how low level stuff works - can they explain what reference equality vs. value equality is, can the explain how the Dictionary works?
It then leads to another question:
And this question tests how they can extend an existing class, and whatever they can come up with something that fits into the .Net idioms cleanly. Adding a boolean to check for an employee name is not a good way to do this.
Here is what I would consider an excellent implementation (not great, because it doesn't implement ICollection<T>):
public class EmployeesSet : IEnumerable<Employee>
{
Dictionary<Employee, object> internalDic;
public EmployeesSet()
{
internalDic = new Dictionary<Employee, object>();
}
public EmployeesSet(IEqualityComparer<Employee> comparer)
{
internalDic=new Dictionary<Employee, object>(comparer);
}
public void Add(Employee item)
{
if(!Contains(item))
internalDic.Add(item,null);
}
public bool Contains(Employee item)
{
return internalDic.ContainsKey(item);
}
public bool Remove(Employee item)
{
return internalDic.Remove(item);
}
public int Count
{
get { return internalDic.Count; }
}
public IEnumerator<Employee> GetEnumerator()
{
return internalDic.Keys.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return internalDic.Keys.GetEnumerator();
}
}
Comments
Comment preview