Top 26 coding questions to crack the Microsoft interview
Tags: career, programming, productivity
Published: 2022-05-13 19:12:42

Aiming for a career at Microsoft is a worthy challenge given the company's excellent track record for technological innovation, generous compensation packages, and flexible work-life balance. 

As the largest and arguably most influential software company in the world, prospective applicants may find the technical interview process daunting. However, familiarizing yourself with the type of technical questions that will be presented to you and learning to recognize coding patterns will help you navigate these interviews with greater confidence. 
 
We'll start with an introduction to 26 common coding questions, move on to an overview of the complete interview process for software engineers, move on to frequently asked technical questions, and then wrap up with additional guidance and resources to maximize your chances of receiving an offer.

**Topics covered**:
- [26 common coding questions](#questions)
- [Overview of the Microsoft hiring process](#overview)
- [How to prepare for the interview](#prep)
- [Wrapping up and helpful resources](#wrapup)

<a name="questions"></a>
## 26 common coding questions
<br>
As you go over each question, get into the habit of diagramming the problem before jumping straight to writing code. Breaking down a problem first gives you a chance to ask questions and get any important information you need to come up with the best possible solution. Take a moment to explain your thought process to yourself as if you were the interviewer.
 
Take some time to reflect on the efficiency of your solution, and try to see if you can make your answer more elegant by simplifying it. 

Lastly, always remember to validate your solutions. 

Alright, let’s dive in! 


### Arrays 
#### 1. Find the missing number in a given array
**Problem Statement**: Given an array of positive numbers ranging from 1 to `n`, such that all numbers from 1 to `n` are present except one number `x`, find `x`. Assume the input array is unsorted.


![Arrays](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eaze8m2iz6lg776asdrr.jpg)

#### 2. Determine if the sum of two integers is equal to a given value
**Problem Statement**: Given an array of integers and a value, determine if there are any two integers in the array whose sum is equal to the given value. Return true if the sum exists, and false if it does not. Consider the following array and its target sums: 


![Integer sums](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/drr0giudbyc8sixvczsb.jpg)

#### 3. Set columns and rows as zeroes
**Problem Statement**: Given a two-dimensional array, if any element within is zero, make its whole row and column zero. Consider the matrix below.   


![Matrix](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/leybunuqprast12jx1ar.jpg)

There are two zeros in the input matrix at positions (1,1) and (2,3). The output of this should be a matrix in which the first and second rows become zero and the first and third columns become zero. Below is the expected output matrix.


![Excepted output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mke2jbqqostaac1evrgx.jpg)

### Linked Lists
#### 4. Add two integers
**Problem Statement**: Given the head pointers of two linked lists where each linked list represents an integer number (each node is a digit), add them and return the resulting linked list. In the example below, the first node in a list represents the least significant digit. 


![Linked lists](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5febuwi7r5ww92f2lqau.jpg)

#### 5. Copy linked list with arbitrary pointer
**Problem Statement**: You are given a linked list where the node has two pointers. The first is the regular `next` pointer. The second pointer is called `arbitrary_pointer` and it can point to any node in the linked list.

Here, deep copy means that any operations on the original list (inserting, modifying, and removing) should not affect the copied list.

Here’s an example of a linked list with arbitrary pointers connected.


![Arbitrary pointer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6hrd1yd52n9xoni5n7g.jpg)

#### 6. Merge two sorted linked lists
**Problem Statement**: Write a function that takes two sorted linked lists and merges them. The function should return a single, sorted list made from splicing the nodes of the first two lists together. 

For example, if the first linked list is `1 -> 2 -> 4` and the second linked list is `3 -> 5 -> 6`, then the output would be `1 -> 2 -> 3 -> 4 -> 5 -> 6` 

### Trees

#### 7. Level order traversal of binary tree
**Problem Statement**: Given the root of a binary tree, display the node values at each level.


![Binary tree](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ixe8fbx20kq35psd588o.jpg)

The level order traversal for this binary tree looks like this:
```
100
50, 20
25, 75, 350
```

#### 8. Connect all siblings
**Problem Statement**: Connect the sibling pointer to the next node in the same level. The last node in each level should point to the first node of the next level in the tree. 


![connected siblings in linked tree](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wtumun89f32cqn4j8fmj.jpg)

#### 9. Check a given binary tree for symmetry
**Problem Statement**: Given a binary tree, write a program that will return true if the binary tree is a mirror image of itself, and false if it is not. 


![Binary tree symmetry](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pksy8y7yf2zt67b2sz84.jpg)

The correct output given this binary tree would be `true` because it is symmetrical. 

### Strings

#### 10. Reverse words in a sentence
**Problem Statement**: Reverse the order of words in a given sentence. 

**Example**:
`"sphinx of black quartz judge my vow"` should output as `"vow my judge quartz black of sphinx"`

#### 11. Find all palindrome substrings
**Problem Statement:** Given a string, find all non-single letter substrings that are palindromes.

**Example:**

An string input of `"poppopo"` would return `"pop"`, `"opo"`, `"oppo"`, and `"poppop"`.

#### 12. String segmentation
**Problem Statement**: Given a dictionary of words and a large input string, find whether or not the input string can be completely segmented into the words of that dictionary. 

### Dynamic Programming

#### 13. Find the maximum single sell profit
**Problem Statement**: Given a list of daily stock prices (integers for simplicity), return the buy and sell prices that will maximize the single buy/sell profit. If you can't make any profit, try to minimize the loss.

For the below examples, buy (orange) and sell (green) prices for making a maximum profit are highlighted.


![Dynamic programming](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i3wp5adbykajxdby9xun.jpg)

#### 14. Length of longest subsequence
**Problem Statement**: Given a one-dimensional integer array `a` of length `n`, find the length of the longest subsequence that increases before decreasing. 


#### 15. Find the longest path in a given matrix
**Problem Statement**: Given an `n*n` matrix where all numbers are distinct, find the longest path starting from any cell such that all cells along the path increase in order by 1. 


> ##### **Recommended Course**:
> Dynamic Programming (DP) questions can be some of the most challenging questions you'll encounter in your programming interviews. To get more practice in this area, we recommend checking out Grokking Dynamic Programming Patterns for Coding Interviews on Educative.

### Math and Statistics

#### 16. Find the missing number in the array
**Problem Statement**: Given an array of positive numbers ranging from `1` to `n`, such that all numbers from `1` to `n `are present except one number `x`, find `x`. 

The input array is not sorted.


![Array 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1refbe3364rg70vzx2ga.jpg)

#### 17. Find all sum combinations
**Problem Statement**: Given a positive integer, `target`, print all possible combinations of positive integers that sum up to the `target` number.

For example, if we are given input ‘5’, these are the possible sum combinations.
```
1, 4
2, 3
1, 1, 3
1, 2, 2 
1, 1, 1, 2
1, 1, 1, 1, 1
```
The output will be in the form of a list of lists or an array of arrays. Each element in the list will be another list containing a possible sum combination.

#### 18. Find the `kth` permutation
**Problem Statement**: Given a set of `n` variables, find their `kth` permutation. Consider the following set of variables:


![Array 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0ab8o3tcyp9e2cb8np9h.jpg)

### Backtracking

#### 19. Regular expression matching
**Problem Statement**: Given a text and a pattern, determine if the pattern matches the text completely or not at all using regular expression matching. Assume the pattern contains only two operators: `.` and `*`. Operator `*` in the pattern means that the character preceding `*` may not appear or may appear any number of times in the text. Operator `.` matches with any character in the text exactly once.

Below is an example of a text and its matching and non-matching patterns.


![Backtracking](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34prdvdxs0h8gfxfosgj.jpg)


#### 20.  Rat in a Maze  
**Problem Statement**: Consider a rat placed in a square `n*n` matrix at position `(0, 0)`. Find all possible paths the rat can take to reach its destination `(N-1, N-1)` from its starting position. 

The rat can move vertically and horizontally. Cells with a value of 1 can be traversed, while cells with a value of 0 cannot. The rat cannot visit a cell more than once.  

#### 21. Solve the Sudoku
**Problem Statement**: Given a square matrix grid of `9*9` and configured to represent an incomplete Sudoku puzzle, find a solution that returns a true or false value depending on whether or not the Sudoku can be completed. If a solution is possible, your solution must also return the completed grid. 

### Graphs

#### 22. Clone a directed graph
**Problem Statement**: Given the root node of a directed graph, clone this graph by creating its deep copy so that the cloned graph has the same vertices and edges as the original graph.

#### 23. Conduct a Breadth-First Traversal of a given graph
**Problem Statement**: Starting from the source node, traverse a given graph breadthwise to find the distance between the source node and node `n`. 

#### 24. Check if there’s a path from a source to its destination
**Problem Statement**: Given a graph `n*n` with each cell containing a value of `0`, `1`, `2`, or `3`, return a `true` or `false` value depending on whether or not one can find a path from the source node to the destination node. Each graph will have one source node and one destination node. The graph can be traversed horizontally and vertically.

The cell containing a value of `0` is the source node.
A value of `1` represents a wall; this node is impassable. 
A value of `2` represents a blank cell that can be traversed.
A value of `3` represents the destination node. 

### Sort and Search

#### 25. Find the closest meeting point
**Problem Statement**: Given `n` people on a square grid, find the point that requires the least total distance covered by all people to meet at that point.

#### 26. Search for the given key in a two-dimensional matrix
**Problem Statement**: 
We are given a two-dimensional array where all elements in any individual row or column are sorted. In such a matrix, we have to search or find the position of a given key.

### Be prepared to go over

- **Data structures**: Arrays, strings, queues, lists, linked lists, stacks, trees, heaps, hash tables, hash maps, hash sets, graphs, and more. 
- **Algorithms**: Breadth-first search, depth-first search, binary search, quicksort, mergesort, dynamic programming, divide-and-conquer, and more. 

> If you have over 3 years of experience developing software, it is highly likely that you will be asked system design questions, which can be more open-ended. <br> <br> To get an idea of what to expect from a system design interview, check out the Top 10 system design interview questions for software engineers on Educative. 

<a name=”overview”></a>
## Overview of the Microsoft hiring process

The timeline for the entire process (from submitting your resume to receiving a job offer) takes approximately 1-2 months You are encouraged to use whatever mainstream programming language (e.g., C/C++ or Java) that you are most comfortable with to solve the technical questions. 

### Interviews
- **Prescreening**: A recruiter contacts you via email to schedule a 45-minute phone call. They will spend 15 minutes going over your resume and asking behavioral questions. You have the remaining 30 minutes to solve a coding question related to algorithms and data structures in a shared editor. 
- **Phone interview**: The recruiter contacts you within two weeks to schedule a phone interview with a senior developer or engineering manager. Information about potential topics that may be covered during this phone interview will be provided in advance.
- **On-site or virtual interview**: After passing the phone interview, you will be invited to participate in 4-5 rounds of interviews either in-person at the Microsoft campus or virtually. Each round is an hour long and will be conducted by two members of the team you're looking to join. These rounds will have both behavioral and technical questions. 
- **Lunch interview**: Halfway through the rounds, you will be taken out to lunch for a more casual conversation. This will take place on the Microsoft campus, or off-campus at a restaurant.   
- **Final interview of the day**: The last round will be conducted by an AS-AP (As-Appropriate) who will have the final say in hiring you.
- **HR interview**: The hiring manager will go over any remaining behavioral or technical questions not covered in the previous rounds of interviews, make an offer, and discuss compensation. 

<a name=”prep”></a>
## How to prepare for the interview

Microsoft develops a holistic view of you as a candidate using competency-based questioning in addition to your resume. They want candidates with strong technical skills that align well with the company values.


![Microsoft interview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ga7abzs6nsue0jzm3h30.jpg)

### Step 1: Update your resume
The first thing you want to do is to make sure your resume and LinkedIn profile are up to date. Be very specific, and use deliverables and metrics whenever possible. 

Next, you’ll want to look at your resume in the context of the Microsoft Core Competencies. Consider how specific projects or experiences can be tied into different Core Competencies, and update them to reflect ways in which you have prioritized these values in your work. 

### Step 2: The 12-week interview prep roadmap
To fully prepare yourself for the coding interview, we strongly suggest that you take **three months** to go over technical concepts and practice solving interview questions. Using an interview prep roadmap is a great way to keep track of your progress, and break down what you need to learn. 

You can use our Definitive Interview Prep Roadmap on Educative to make sure you’re hitting all of the important topics that might be covered during coding interviews.   
- **Week 0** - What programming language should you use?
- **Week 1** - Brush up on your chosen programming language.
- **Weeks 2 & 3** - Data structures and algorithms.
- **Weeks 4 & 5** - Practice simple data structures and algorithmic challenges
- **Weeks 6, 7 & 8** - Dive into more complex coding interview problems
- **Weeks 9 & 10** - System design interviews
- **Week 11** - OS and concurrency concepts
- **Week 12** - Object-oriented design interviews

### Step 3: Prepare for the behavioral interview 
Behavioral interview questions typically fall into one of three categories: 
- Past experiences
- Hypothetical situations
- Values-based questions 

Behavioral interviews help interviewers decide if you’re someone they would want to work with. Reflect on how you react to positive situations or conflicts in a professional setting, and be honest about your past experiences. Essentially, be your authentic self.

Don’t be afraid to bring your unique perspective to the table. Go beyond just answering questions. Really listen and respond to your interviewers. Show them that you’re engaged and tuned into the conversation you’re having with them. 

The most important thing to keep in mind for any behavioral interview is that your interviewers *want* to hire you. If you’re enthusiastic about the technology you’ll be working with, don’t be afraid to show it! 

> If you want to brush up on behavioral interview questions, then check out Grokking the Behavioral Interview on Educative to learn more about what interviewers are looking for, and how you can develop the kind of structured responses that impress them.

You can also read up about the [key attributes](https://careers.microsoft.com/us/en/culture) that define the culture at Microsoft. 

<a name=”wrapup”></a>
## Wrapping up and helpful resources

Now that you're more familiar with the Microsoft interview process, it's time to make a plan and put it into action! The best candidates come **fully** prepared, so it's important to exercise due diligence. We've put together an extensive course that will help you quickly identify any gaps in your knowledge, test your skills, and practice using a live, in-browser coding environment. 

Check out Grokking the Coding Interview: Patterns for Coding Questions on Educative.

You can visit our Decode the Coding Interview library on Educative. The Decode series exposes you to some of the most frequently asked questions at tech companies and helps solidify your knowledge by contextualizing these problems in real-world applications.  

*Happy learning!*

### Related courses on Educative
- [Ace the C++ Coding Interview](https://www.educative.io/path/ace-cpp-coding-interview?eid=5082902844932096)
- [Ace the Java Coding Interview](https://www.educative.io/path/ace-java-coding-interview?eid=5082902844932096)
- [Ace the Python Coding Interview](https://www.educative.io/path/ace-python-coding-interview?eid=5082902844932096)
- [Ace the JavaScript Coding Interview](https://www.educative.io/path/ace-javascript-coding-interview?eid=5082902844932096)

### Related articles on Educative

- [Top 5 hardest coding questions from FAANG recent interviews](https://www.educative.io/blog/hardest-coding-interview-questions?eid=5082902844932096)
- [Top 7 salary negotiation tips for software developers](https://www.educative.io/blog/salary-negotiation-tips-for-software-developers?eid=5082902844932096)
- [How to ace a coding interview even if you can't solve the problem](https://www.educative.io/blog/ace-coding-interview?eid=5082902844932096)
- [Top 10 system design interview questions for software engineers](https://www.educative.io/blog/top-10-system-design-interview-questions?eid=5082902844932096)

#### Educative Unlimited

If you like our content, consider signing up for Educative Unlimited today! 

### Start a discussion 
What tips do you have for the Microsoft interview? Was this article helpful? Let us know in the comments below!