Microsoft Interview Question for Software Engineer / Developers


Team: yammer
Country: United States




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

looks like merging n sorted lists . k-waymerge could solve the problem

- alok.net October 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Did you consider lists like this as possible inputs too?

{{1,2, {9,7}}, {3}, {4,5}}

- bp February 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

For any order of numbers in the list, it should support.
I think creating a min heap for the given input and then creating a list by popping the values would give us the proper result.

For n values, creation will take O(n) for min heap. Creating the result array requires popping top element which includes min heap adjustment of O(log n) levels per number. Hence O(n log n)

There can be a more better approach than this. I just gave my thought :)

- Sunil May 13, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 3 vote

In python using list comprehensions:
arr = [[1,2],[3],[4,5]]
[num for elem in arr for num in elem]

>> [1,2,3,4,5]

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

Just to clarify, is it allowed to change the data structure? Or just implement like iterator to flattenly access to the elements?

- maillist.danielyin October 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public List<Integer> flattenList(List<List<Integer>> listOfList) {
		List<Integer> flattenList = new ArrayList<Integer>();
		
		for(List<Integer> list: listOfList) {
			flattenList.addAll(list);
		}
		return flattenList;
		
	}

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

public static List<T> FlattenList<T>(List<List<T>> inputList)
        {
            return inputList.SelectMany(x => x).ToList();
        }

- Ben November 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

l = [[1,2], [3], [2,4,5], [6], [4,5,7,4]]
l1 = list(l) #Copy of l
e = []

for i in l:
    l2 = l1.pop(l1.index(i))
    for j in l2:
        e.append(j)
        
print e

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

[item for ilist in lst for item in ilist]

- Anonymous September 09, 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