Saturday, June 21, 2008

Svetlin Nakov Microsoft interview experience

In his least post Svetlin Nakov writes that he rejected a program manager position at Microsoft Dublin even though he succeed in interview. While his rejection was based only on several times lower salary than he already had, we who would like to work at Microsoft at some time could learn.

Svetlin has posted all questions that he was asked at interview in Microsoft, because he wasn't asked to sign any NDA agreements.

Svetlin gives some examples of interview questions at Microsoft starting from basic ones:

Question 5: What is SQL injection? SQL injection is vulnerability coming from dynamic SQL created by concatenating strings with an input coming from the user, e.g. string cmd = “SELECT * from USERS where LOGIN=’” + login + “‘ and PASS=’” + password + “‘”. if username has value “‘ OR 1=1 ‘;”, any login / password will work. To avoid SQL injection use parametric commands or at least SQL escaping.
To medium difficulty:
Question 11: How you write a distributed Web crawler (Web spider)? Think about Windows Live Search which crawls the Internet every day. You have a queue of URLs to be processed and asynchronous sockets that process the URLs in the queue. Each processing has several states and you describe them in a state machine. Using threads with blocking sockets will not scale. You can still use multiple threads if you have multiple CPUs. The Web crawler should be stateless and keep its state in the DB. This will allow good scalability. A big problem is how to distribute the database. It is very, very large database. The key here is to use partitioning, e.g. by site domain. Take the site domain, compute a hash code and distribute the data between the DB nodes based on the hash code. No database server can store all the pages in Internet, so you should use thousands of DB servers and partitioning.
You can read other questions on his blog. To me these questions are actually very easy. Am I so good that I even don't see a challenge or there is something else here? I will find out only when Microsoft invite me for an interview I guess :) There is one other thing that touched me. The answer to second question is brilliant.
Question 2: You are given a string. You want to reverse the words inside it. Example “this is a string” –> “string a is this”. Design an algorithm and implement it. You are not allowed to use String.Split. After you are done with the code, test it. What will you test? What tests you will write? Elegant solution in 2 steps: 1) Reverse whole the string char by char. 2) Reverse again the characters in each word. You need to write a method Reverse(string s, int startPos, int endPos). Test normal cases first (middle of the word, beginning of the word, end of the word, 1 character only, all letters in the string). Check bounds (e.g. invalid range). Test it with Unicode symbols (consisting of several chars). Perform stress test (50 MB string). Write a method ReverseWords(string s). Test it with usual cases (few words with single space between), with a single word, with an empty string, with words with several separators between. Test it with string containing words with capital letters.
Svetlin, have you seen the answer somewhere before, or did that just hit upon you? A truly elegant solution I must say. Other answers were good too, though sometime I would offer other solutions. I am glad that that you didn't accept the offer. After all programmers are we : if(newSalary > currentSalary && newChallengeRate == currentChallangeRate) { currentJob.Stay(); }

No comments: