Microsoft Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
2
of 2 vote

Treat a birthdate as a string formatted as "yyyymmdd". for example, "Feb 9th, 1980" is converted into a string of "19800209". Now use this string as the key of each family member. Keys are compared according to the following lexicographic order. 0<1<2<3...<9. In-order traversal suffices to print out the names from oldest to youngest.

- BST February 14, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use a linked list.
Node - Name + Date of Birth (Just for printing) + Num of days from 1900

- Srik June 14, 2005 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you can store use birthdates formatted as (year, month, day) as keys to element in the list of family members.
Now first sort the list based on day, then sort the list based on month and then sort the list based on year.

You would have all birthdates in sorted order.

The sort would take O(3nlogn). You can optimize this using bucket sort. You can do it in O(n) but with bucket space

- WonderSorter June 23, 2005 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

how about inserting into the linked list in a sorted manner based on the date.

- Seshagiri July 24, 2005 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Member {

String name;
Date birthDate;

public:

Member(String name, Date birthDate)
{/* .... */}
}

class Family {
public:
void addMember(Member familyMember)
{ /* .. add it to a max heap based on birthDate .. */ }
void printNames()
{
while(heap ! Empty)
print(heap->remove());
}
}

Order analysis:
===============
adding takes O(nlogn). n is the number of members. each addition takes logn to re-heapify.
printing takes O(n). therefore approximately O(nlogn)

- srihari December 31, 2005 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A date class already exists in some form or another in a library. Hence, create a composition containing a person's family dates. The aggregation will use a Binary Search Tree to maintain order. Each date has a hash value that you can use for ordering. Insertion is O(logn). Traversal is O(n).

- Jack February 15, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Testing:

case 1:Insert three duplicate dates.
case 2:Insert 3 sequential dates from low-high.
case 3:Insert 3 sequential dates from high-low.
case 4:Insert 3 dates out of order.

- Jack February 15, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Along with the idea of BST - I guess a TRIE structure will be faster. Since the length of the input is fixed to 8 digits always, an insertion, lookup is O(1). We can print all elements in non decreasing order in O(n) time. Care should be taken to maintain the TRIE with year digits first, month digits next and then date digits...

- Shireesh February 27, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I agree with BST.

insertion O(logn), lookup O(logn)
print will be reverse inorder traversal (right, root, left) O(n)

linked list insertion O(n) lookup O(n)
print iteration O(n)

- visitor April 18, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

BST keeps data in sorted fashion & does not allow duplicate Node data; here node data to compare is Birth Date. It may happen in a family more that 1 persons may have same Birth date; so while inserting data BST will fail.

- AK November 16, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Instead of manipulating a BST directly, wrap it in a HashMap to get O(1) access on top.

- Jack April 18, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class DateOrder
{
System.Collections.Hashtable Dates = new System.Collections.Hashtable();
public void InsertDate(DateTime date)
{
DateTime firstDate = new DateTime(1900,1,1);
TimeSpan difference = date.Subtract(firstDate);
Dates[difference.Days ] = date;
}

public void Print()
{
foreach(DateTime date in Dates.Values )
{
if (! date.Equals(null))
{
Console.WriteLine(date.ToShortDateString());
}
}
}
}

- Altaf Al-Amin Najwani April 22, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Base on the question, we are allowed to use class. So we can define a comparable function for sort function in STL. This function return bool value by comparing the value of year, month and date.
Test cases:
1. Y2k year
2. Months: 12 months
3. Dates: Jan - 31, Feb -28(for leap year 29), ...,
4. All independant methods in Date class(if we write our own)
5. all independant methods in Person(constructor, ...)
6. all independant methods in Familty(constructor, ...)
7. all dependant methods in Person(getBirthDate...)
8. all dependant methods in Familty(comp, sort, printout...)

- James May 09, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i believe we sould count on the finite numbers of years that are possible.
set the oldest one to be 120 years old. than if we are on 2006, than the oldest one was born on 1886 (= START) and if i am going to live another 60 years than the youngest one in my family (that i am going to know) might be borned on (2006+60=2066= END). therefore, i find the most easy way to implement that matter is with an array and link list (in the same manner of hash table connected to link list)
the array index will be arr[START]..arr[END]

ADD operation:
add the date of the person to the arr[year] entry.
if he is the only person in that year add a node to the year.
if he is not the only person, add him to the right place from older to younger.

the performance should be a hash table performance ~ O(1) add, O(1) get element=> 0(n) get all elements
Tests:
test ADD:
1. add to year smaller than START
2. add to year in the future - later than current day
3. add a not valid date, like feb. 30
4. add 2 dates that are equal
5. add a valid date

test getALL:
1. call getAll and compare to your input

- Eila May 27, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

//there will be an integer used to sort the BST and a string used to print.
class Node{
int bday; //integer value used for sorting BST
Node* left;
Node* right;
Char* strBday; // entered as mm/dd/yyyy

// birthday will be entered in form mm/dd/yyyy this function will convert the string to an integer value that will be used to insert into the the familyTree
int convert(char* strBday);
}

class familyTree{

Node* head;
void print();
void insert(Node* person);
void remove(Node* person);
}

- Rastan October 30, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

BST`s idea is best.. trie wont be useful here as it is a good data structure for searching and not for sorting...

- Tushar February 16, 2007 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More