Amazon Interview Question
Developer Program EngineersCountry: India
Interview Type: Written Test
form 12/mar/2011 as 20110312, in this way we can convert all the dates to a number and then can sort them in O(n * log n) time.
enumerate the months.
mainly 3 functions are required
1)convert the given string to dd mm and yyyy format.
2)take a date as reference.from this date, convert all the dates into number of days
3)convert the number of days back to string
you can perform any operation you want sort, add subtract by overloading the operator.
this will surely work
List<string> ar = new List<string>() { "12/mar/2011","15/jan/1990","12/apr/1985","23/dec/1960","11/sep/2004"};
List<DateTime> arDate = new List<DateTime>();
foreach (string date in ar)
{
arDate.Add(Convert.ToDateTime(date));
}
arDate.Sort();
foreach (DateTime dt in arDate)
{
Console.WriteLine(dt);
}
Use Radix sort.
- Punit Jain May 16, 2012