![]() |
|
|
Published: Thursday, January 27, 2000 I recently visited Microsoft's Silicon Valley campus and interviewed with the Hotmail group. If you've never had a Microsoft interview, realize that they are very different than the standard interview. You won't be asked any of those questions like, "What is your greatest weakness," or, "Where do you want to be in five years?" Rather, a Microsoft interview typically contains a number of brain teasers and coding questions. In fact, you can read interview questions from my internship interviews.
Here are the questions I was asked, accompanied with the answers right below the question! So, once you reach the end of the question, don't read any further unless you want to immediately know the answer! Anyway, here goes: Question: How could you determine if a linked list contains a cycle in it, and, at what node the cycle starts?
Answer: There are a number of approaches. The approach I shared is in time N (where N is the number
of nodes in your linked list). Assume that the node definition contains a boolean flag,
Then, to determine whether a node has a loop, you could first set this flag to
Then, to determine whether or not a cycle existed, loop through each node. After visiting a node, set
A much better approach was submitted by 4Guys visitor George R., a Microsoft interviewer/employee. He recommended using the following technique, which is in time O(N) and space O(1). Use two pointers. Thanks George!
Question: How would you reverse a doubly-linked list?
Answer: This problem isn't too hard. You just need to start at the head of the list, and iterate to the
end. At each node, swap the values of
Question: Assume you have an array that contains a number of strings (perhaps Answer:
Begin by sorting each element in the array in alphabetical order. So, if one element of your array was
Next, sort the entire array of
these modified dictionary words. Now, all of the anagrams are grouped together. Finally, step through the
array and display duplicate terms, mapping the sorted letters ( Question: Given the following prototype:
write a function that will take a sorted array, possibly with duplicates, and compact the array, returning
the new length of the array. That is, if Answer: A single loop will accomplish this.
Happy Programming!
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||