OA OA (Online Assessment) There were 2 coding questions for the Online Assessment round of Microsoft. As far as I can remember, almost everyone had different questions.
Question 1: You are given an array and an operation that you can perform on it. In one operation, you can select any two distinct indices i and j, remove arr[i] and arr[j], and add (arr[i] + arr[j]). This operation costs you (arr[i] + arr[j]). What is the minimum cost to reduce the array to a size of 1?
I recommend you try it for at least 5 minutes before moving forward.
This one was a straightforward greedy question where we can always choose the smallest two elements, pop them from the array, and then insert their sum. Continue this n-1 times to reach size 1. (I used a multiset to remove and insert elements, resulting in an O(n log n) approach).
Question 2: You are given n intervals, where l[i] and r[i] are the two boundaries for the interval (and l[i] <= r[i] is guaranteed). You are also given Q queries, where in each query we are given an integer x. We need to answer how many intervals this x falls into.
Constraints: 1 <= l[i], r[i], x <= 1e9 and 1 <= n, Q <= 1e5
You can try this one too before looking at the solution. I used binary search. I sorted the l and r arrays and then simply calculated: (how many intervals can include x - how many intervals have ended before x). This means each query can be answered in O(log n), leading to a total time complexity of O(n log n + Q log n).
Interview Round 1 (Coding Round): The interviewer joined, and I gave my intro. It was an online interview with a fixed slot of 45 minutes, so he quickly jumped to the coding question (which was conducted over HackerRank).
Question: You are given a string of characters, numbers, and symbols. Your task is to find valid substrings of dates (i.e., DD-MM-YYYY) and print them.
I started by asking some clarifying questions, like "Can there be any separator in the date?" He said yes, it can be / or -. Then I asked whether there was a limit on the number of valid dates in a string. (He said "No").
It was quite an implementation-heavy question, and I coded it in around 35-40 minutes. Meanwhile, I explained every single step to the interviewer and frequently checked in to see if he was following my logic. To be honest, there were times when I made some silly errors, and the interviewer even corrected me.
Round 2 (Managerial Round): In this round, a senior engineer with 20 years of experience at Microsoft was the interviewer. I started with my introduction and briefly explained my projects. He picked up on one of my projects related to Operating Systems, and we had a discussion about virtual memory and context switch overhead.
Then, I felt he wanted to check my overall compatibility as a Software Engineer Intern. He gave me a decently long piece of C++ code whose main purpose was to store the names and marks of N different students. Basically, it was a student database. (I don't remember the exact piece of code)
He asked me to debug the code. The program was designed to calculate the average marks, the highest marks, the topper's name, and find the marks of any student given their name (using binary search). The mistakes in the code mainly included logical errors, syntax issues, and incorrect variable initializations.
There were a total of 15 mistakes (as far as I can remember), and I was able to figure out and fix 13 of them.
Throughout the process, I thought out loud, trying to take the interviewer along with me at every single step. He seemed pretty satisfied with my answers. At the end, we discussed the role of an intern at Microsoft and the different teams within the company.
So yeah, that was my interview experience with Microsoft! To prepare for it, I highly recommend being thorough with your projects and CS fundamentals (especially C++ and OS). Most importantly, they really care about how you communicate—basically, how well you can structure your thoughts on the table.