Microsoft Coding Questions

Microsoft coding questions

Microsoft Coding Questions and Answers

On this page, the 2024 Microsoft Coding Questions and Answers are discussed. One of the most crucial rounds for landing a job at Microsoft is the coding round.

You can use this section to analyse the level of complexity of the Microsoft problem. Understanding the level of complexity and question format for the coding phase is made easier by practising Microsoft coding questions and answers.

The Microsoft Coding Round questions and their solutions in different languages can be found below. For a good grade, you must be prepared for the Microsoft code problems.

Microsoft Coding Questions and Answers Test Format

  • Coding round contains 2 questions that will have to be attended in 2 hours.
  • Each questions have different difficulty level.
  • There is one Easy problem based on Algorithm , Aptitude and Data structures.
  • One is of Hard difficulty level, and usually based on Dynamic Programming/Greedy Algorithm
No. Of QuestionsTime limit
Question 160 mins
Question 260 mins

Question 1

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.

Question 2

Problem Statement:

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

 

Question 3

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.

More Microsoft Coding Questions and Answers

Question 4

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.

 Question 5

Problem Statement :

Given the root of a binary tree, display the node values at each level.

Question 6

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.

Question 7

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.

 

Question 8

Problem Statement:

Find the largest continuous sequence in an array which sums to zero.
Example:

Input: {1 ,2 ,-2 ,4 ,-4}
Output: {2 ,-2 ,4 ,-4}

NOTE : If there are multiple correct answers, return the sequence which occurs first in the array,

Question 9

Problem statement: Shifting Letters says that we have given a string s and an array shifts.

Now for each shifts[i] = x, we want to shift the first i + 1 letters of s, x times. We have to return the final string after all shifts are applied.

Example 1:

Input: s = “abc”, shifts = [3,5,9]
Output:”rpl”
Explanation:We start with “abc”.

  • After Shifting the first 1 letter of s by 3, we have “dbc”.
  • After shifting the first 2 letters of s by 5, we have “igc”.
  • After shifting the first 3 letters of s by 9, we have “rpl”.
  • Hence “rpl” is our final answer.

Example 2:

Input: s = “aaa”, shifts = [1,2,3]
Output:”gfd”

Constraints:

  • 1 <= s.length <= 105
  • s consists of lowercase English letters.
  • shifts.length == s.length
  • 0 <= shifts[i] <= 109

Approach

We have to calculate how many times the i-th character is shifted. So just calculate the number of shifts on each position, by shifts[i] += shift[i+1]. We will do the task in reverse order. We have to maintain a  reverse prefix sum of the shift array and this will be equal to the number of shifts for each character. One thing we should focus on is that if we found that our character ASCII score exceeds the value of the ASCII score of ‘z’ we should start counting from ‘a.

 Question 10

Problem Statement :

Find the longest increasing subsequence of a given array of integers, A. In other words, find a subsequence of an array in which the subsequence’s elements are in strictly increasing order, and in which the subsequence is as long as possible. This subsequence is not necessarily contiguous, or unique. In this case, we only care about the length of the longest increasing subsequence.

Input Format:

  • The first and the only argument is an integer array A.

Output Format:

  • Return an integer representing the length of the longest increasing subsequence.

Constraints:

  • 1 <= length(A) <= 2500
  • 1 <= A[i] <= 2000

Example :

Input : A = [1, 2, 1, 5]
Output : 3
Explanation :The sequence : [1, 2, 5]

 

Input :A = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]
Output : 6
Explanation : The sequence : [0, 2, 6, 9, 13, 15] or [0, 4, 6, 9, 11, 15] or [0, 4, 6, 9, 13, 15]