Microsoft Interview Question for SDE1s


Country: India
Interview Type: Phone Interview




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

Can we use a trie tree to store the # of people visited based on the country/state/city name (suppose their names are unique)

- yingzhong.xu October 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

Exactly what came to my mind.

You could construct a multiple Trie structure as follows :
The last node of each country in the CountryTrie would contain an object that maintains the count of the visit + another StateTrie object maintaining the states for the country.
And each state in the StateTrie would similarly contain an object maintaining a CityTrie+count.
I'm guessing this would save us a lot of space.

- teli.vaibhav October 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The first thing that comes to mind is a hash table with linked list chaining. You hash the entire dataset on whatever field you want to count hits from. Fields that are filled out the same will hash into the same bucket and the length of the linked list will equal to the number of fields hashed into the bucket.

Since adding to linked lists is pretty crappy in terms of time complexity, it probably makes more sense to use something like a dynamic array instead of a linked list, but the main concept is the same either way. I'm not sure what the best way to handle the size of table, though, since you have to be sure that two fields of the same type can't be hashed into the same slot.

- Conor Hetland October 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If you used dynamic arrays you'd have to be careful to keep track of the number of elements in the array, and not the size of the array, but you probably have to do that anyway to implement a dynamic array (I forget).

- Conor Hetland October 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Make three strucs
Country { Name; }
State { Country; StateName;}
City { State, CityName)
2. Make BStree Country, State, City
3. When there is any change in city it also add in State and Country also.
4. When any element change System should adjust in BStree so when user get allways get result in order.

- Kulwinder October 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use k-d tree. Kd- Tree solves multi dimensional search problem.

- Stupid Developer October 27, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use Hash maps inside Hash maps.

e.g. in C++

struct StateData {
   map<string, int> CityData;
   int StatePeopleCount;
}

struct CountryData {
   map<string, StateData*> StateData;
   int CountryPeopleCount;
}

map<string, CountryData*> CountryDataHash;

- subrat.iitkgp October 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Multi level Hashing

Country -> State -> City

- smashit December 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Put the data into a DB and you are good:) However, If you prefer a fancy data structure, I would use Trie.

- tian February 28, 2014 | 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