most common microsoft coding interview questions

Below is a list of the 15 most frequently asked questions in a microsoft interview 

For detailed solutions to each question, you can visit
Grokking the Coding Interview: Patterns for Coding Questions

 

Arrays

determine if the sum of two integers is equal to the 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.

set columns and rows as zeros

Problem Statement

Given a two-dimensional array, if any element within is zero, make its whole row and column zero.

 

linked lists

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.

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.

 

Your job is to write code to make a deep copy of the given linked list. Here, deep copy means that any operations on the original list (inserting, modifying and removing) should not affect the copied list.

 

trees

Given a binary tree, perform a zigzag level order traversal

Problem Statement

Given a binary tree, populate an array to represent its zigzag level order traversal. You should populate the values of all nodes of the first level from left to right, then right to left for the next level and keep alternating in the same manner for the following levels.

perform a level order traversal of a binary tree

Problem Statement

Given the root of a binary tree, display the node values at each level. Node values for all levels should be displayed on separate lines.

 

strings

reverse words in a sentence

Problem Statement

Reverse the order of words in a given sentence(an array of characters).

find all palindrome substrings

Problem Statement

Given a string find all non-single letter substrings that are palindromes.

 

dynamic programming

find maximum single sell profit

Problem Statement

Given a list of daily stock prices (integers for simplicity), return the buy and sell prices for making the maximum profit. You need to maximize the single buy/sell profit. If you can't make any profit, try to minimize the loss.

 

Math and stats

find the missing number in the array

Problem Statement

You are given an array of positive numbers from 1 to n, such that all numbers from 1 to n are present except one number 'x'. We have to find 'x'. The input array is not sorted.

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.

 

backtracking

regular expression matching

Problem Statement

Given a text and a pattern, determine if the pattern matches with the text completely or not at all by using regular expression matching. For simplicity, assume that the pattern may contain 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.

 

Graphs

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.

 

sorting and searching

find the median of the sliding window

Problem Statement

Given an array of numbers and a number ‘k’, find the median of all the ‘k’ sized sub-arrays (or windows) of the array.

search for the given key in a 2d matrix

Problem Statement

We are given a 2D 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.

For detailed solutions to each question, you can visit
Grokking the Coding Interview: Patterns for Coding Questions

have you been asked a question that is not included here in your microsoft interview? 

please share with us:

map_icon.png

Need help preparing for the interview?

Check out the Definitive Interview Prep Roadmap,

written and reviewed by real hiring managers.