Microsoft Corporation
700+ Interview Questions and Answers
You are given a vector of 'N' integers denoting the number of buses that can be boarded from the i-th position. The bus stops only at stops whose number is a multiple of the bus stop number from which the ...read more
Chess tournament is going to be organized in Ninjaland. There will be C chess players going to attend the tournament. All the players will be staying in a hotel. The hotel has N free room...read more
Write a function that calculates the corresponding day of the week for any particular date in the past or future.
For example, for the date 28th August 2020 happens to be Friday. Hence the expect...read more
There are ‘n’ fruit trees that are planted along a road. The trees are numbered from 0 to n-1. The type of fruit each tree bears is represented by an uppercase character of the English alphabe...read more
You are given two Strings 'P' and 'Q' of equal length. Your task is to check whether String 'P' can be converted into String 'Q' by cyclically rotating it to t...read more
There are ‘N’ people at a party. Each person has been assigned a unique id between 0 to 'N' - 1(both inclusive). A celebrity is a person who is known to everyone but does not know anyone at...read more
You are given an array of 'N' integers denoting the heights of the mountains. You need to find the length of the longest subarray which has the shape of a mountain.
A mountain subarray ...read more
Q8. You are given infinite sequence of continuos natural numbers-1,2,3,4,5,6.......... Initially you delete every 2nd element so sequence will be 1,3,,5,7,9,11,13..... now in the resultant sequence you delete every...
read moreProgram to check if a given number is a lucky number or not.
Create a function that takes an integer n as input
Initialize a variable count to 2
Loop through the sequence and delete every count-th element
Repeat the above step until the end of the sequence
If n is present in the final sequence, return true, else return false
Design and implement a data structure which supports the following operations:
insert(X): Inserts an element X in the data structure and returns true if the ...read more
You are given the first term (A), the common ratio (R) and an integer N. Your task is to find the Nth term of the GP series.
The general form of a GP(Geometric Progression) series is A, A(R...read more
You are given ‘N’ words of various lengths, now you have to arrange these words in such a way that each line contains at most ‘M’ characters and each word is separated by a space character. The cost of...read more
You are given an array Arr consisting of n integers, you need to find all the distinct triplets present in the array which adds up to zero.
An array is said to have a triplet {arr...read more
You are given an array of strings. Your task is to find the number of unique strings.
A string is considered unique if it cannot be formed from any other strin...read more
You are given an array consisting of 'N' distinct positive integers and a number 'K'. Your task is to find the kth largest element in the array.
Example:
Consider the ar...read more
You are given D dice, each having F faces numbered 1 to F, both inclusive. The task is to find the possible number of ways to roll the dice together such that the sum of face-up numbers equal the give...read more
You're given a string 'STR' containing ‘0’, ‘1’ and ‘?’ special characters. Your task is to generate all the strings that are possible by replacing the special character ...read more
You have been given a binary tree of integers. Your task is to calculate the sum of all the leaf nodes which are present at the deepest level of this binary tree. If there are ...read more
You are given a singly Linked List of integers. Your task is to return true if the given singly linked list is a palindrome otherwise returns false.
For example:
The given linked list is 1...read more
You are given an array (ARR) of length N, consisting of integers. You have to find the sum of the subarray (including empty subarray) having maximum sum among all subarrays.
A subarray is a...read more
You are given an array 'ARR' of integers of length N. Your task is to find the first missing positive integer in linear time and constant space. In other words, find the lowest positive in...read more
You are given a positive integer 'N'. Your task is to find the number of strings of length ‘N’ that can be formed using only the characters ‘a’, ‘b’ and ‘c’. The strings formed should be such that ...read more
You have been given an Encrypted String where repetitions of substrings are represented as substring followed by the count of substrings.
Example: String "aabbbcdcdcd" wi...read more
You are given a string “S”. Your task is to rearrange the characters of a string “S”, such that it does not contain any two adjacent characters which are the same.
If it is possible to rearrange...read more
You have given a Singly Linked List of integers, determine if it forms a cycle or not.
A cycle occurs when a node's next points back to a previous node in the list. The linked li...read more
You are Harshad Mehta’s friend. He told you the price of a particular stock for the next ‘N’ days. You can either buy or sell a stock. Also, you can only complete at most 2-transactions. Find...read more
You have been given a singly linked list which may or may not contain a cycle. You are supposed to return the node where the cycle begins (if a cycle exists).
A cycle occurs whe...read more
You have been given an integer 'N'. Find the nearest multiple of 10 to the given integer 'N'.
Note:
If there are multiple answers, find the smallest one. For example, if N = 35, both 30 an...read more
Given a sequence of numbers ‘ARR’. Your task is to return a sorted sequence of ‘ARR’ in non-descending order with help of the merge sort algorithm.
Example :
Merge Sort Algorithm - Merge sort is a Div...read more
You are given an array 'ARR' of 'N' integers and you have to calculate 3 things for the given array:-
1. Mean - function mean(): This function should calculate the mean of the ...read more
You are given an arbitrary binary tree consisting of N nodes where each node is associated with a certain integer value from 1 to 9. Consider each root to leaf path as a number.
For example:
1 ...read more
The Look-And-Say sequence is a sequence of positive integers. The sequence is as follows:
1, 11, 21, 1211, 111221, 312211, 13112221,...
This sequence is constructed in the following way:
Th...read more
You are given D dice, each having F faces numbered 1 to F, both inclusive. The task is to find the possible number of ways to roll the dice together such that the sum of face-up numbers equal the giv...read more
You are given an integer 'N'. For a given 'N' x 'N' chessboard, find a way to place 'N' queens such that no queen can attack any other queen on the chessboard.
A queen can be killed when it lies in the ...read more
You are given a binary tree consisting of integer values. Your task is to convert the given binary tree into a linked list where the nodes of the linked list follow the same order as the pre-...read more
Given a string 'S' and a list 'wordList' that consists of 'N' distinct words. Let 'Wi' denote word at index 'i' in 'wordList'. For each word 'Wi' in 'wordList', you n...read more
You are given a string “S” containing only digits from 0 to 9. Your task is to find all possible IP addresses that can be obtained from S in lexicographical order. If no valid IP address can be genera...read more
Q37. You have a cuboid (m*n*p) each block of the cuboid is having a metallic ball. Now we are passing X-ray from front face and getting a bool matrix1 of m*p the elements are set if there is a black spot.(as we are ...
read moreYes, it is possible to get the accurate result from the given data.
The coordinates (i,j,k) where metallic balls are present can be determined by finding the set elements in both matrix1 and matrix2.
Additional data is not required as the given data is sufficient to determine the coordinates.
The coordinates can be obtained by iterating through the elements of matrix1 and matrix2 and checking for set elements.
You have been given string 'S' of length 'N' that may contain duplicate alphabets. Your task is to return the count of distinct subsequences of it.
For example:
For the given st...read more
You have been given two singly Linked Lists, where each of them represents a positive number without any leading zeros.
Your task is to add these two numbers and print...read more
You are given a matrix ‘ARR’ having dimensions ‘N*M’. Your task to find the rank of the matrix ‘ARR’.
The rank of a matrix is defined as:
(a) The maximum number of linearly independent column vectors i...read more
You are given an array(ARR) of length 'N', consisting of non-negative integers. Using only these given numbers, rearrange the numbers in such a way that th...read more
You are given some information about the rooms of a military camp. The rooms are numbered from 0 to 'N-1'. Each room contains keys to some other rooms. You can visit a room only if you have a key to that r...read more
You are given a list of “N” strings A. Your task is to check whether you can form a given target string using a combination of one or more strings of A.
Note :
You can use any string of A multiple tim...read more
You have been given the prices of 'N' stocks in an array where each array element represents the stock price for that day. You need to find the maximum profit which you can make by buyin...read more
You are given a non-empty binary tree where each node has a non-negative integer value. Return the maximum possible sum of path between any two leaves of the ...read more
You have been given the preorder and inorder traversal of a binary tree. Your task is to construct a binary tree using the given inorder and preorder tra...read more
You have been given an array/list of strings 'inputStr'. You are supposed to return the strings as groups of anagrams such that strings belonging to a particular group are anagrams of one another....read more
You are Harshad Mehta’s friend. He told you the price of a particular stock for the next ...read more
You have given a singly linked list and two integers 'N' and 'M'. Delete 'N' nodes after every 'M' node, or we can say more clearly that traverse the linked list suc...read more
You are given a path to a file/directory in Unix-style of length N, In a Unix-style file system, a dot(.) refers to the current directory. A double dot(..) refers to the previous directory...read more
Given a number ‘grayNumber’. Find the gray code sequence.
Conditions for a gray code sequence :
1. Gray code sequence contains numbers from 0 to 2^'grayNumber'-1 in bit/binary form. 2. Two consecutive ...read more
Two trains, separated by a distance of 80km, are running towards each other on the same track at a speed of 40 kmph. A bird takes its flight from train X and flies towards train Y at a con...read more
Ninja is given a few numbers, and he is being asked to rearrange the numbers so that every second element is greater than its left and right element.
Input Format:
The first line of...read more
You are given a stream of 'N' integers. For every 'i-th' integer added to the running list of integers, print the resulting median.
Print only the integer part of the median.
Input Format :
The fi...read more
You have been given a binary tree of 'N' unique nodes and a Start node from where the tree will start to burn. Given that the Start node will always exist in the tree, your task is to print the...read more
You are given an array of integers 'ARR' of size 'N' and another integer 'K'. Your task is to find and return 'K'th smallest value present in the array.
Note: All the elements in the array a...read more
Let A[0 ... n-1] be an array of n distinct positive integers. If i < j and A[i] > A[j] then the pair (i, j) is called an inversion of A (where i and j are indexes of A). Given an integer array A...read more
Ninja is learning tree data structure these days. While learning, she came across learn about the Binary Search tree. She found BST quite interesting. She decided to make her own Binary Search...read more
There are two singly linked lists in a system. By some programming error, the end node of one of the linked list got linked to the second list, forming an inverted Y shaped list. Wri...read more
You are given two arrays of coefficients and degrees of a polynomial expression. You need to simplify the polynomial in general form by evaluating and simplifying the expression.
For Exam...read more
Given a binary tree. Print the Left View of the Tree.
Example :
If the input tree is as depicted in the picture:
The Left View of the tree will be: 2 35 2
Input format :
Elements in t...read more
You are given a single non-negative integer ‘N’ who’s binary representation consists of a single ‘1’ digit and the rest of the digits are ‘0’s. Your task is to find the position of the only...read more
You are given a list of ‘transactions’ between ‘n’ number of friends. who have to give each other money. The list consists of data of receiver, sender, and transaction.
Your task is to minimiz...read more
You have been given two integers ‘X’ and ‘Y’ which are the first two integers of a series and an integer ‘N’. You have to find the Nth number of the series using the Fib...read more
For a given two strings, 'str1' and 'str2', check whether they are a permutation of each other or not.
Permutations of each other
Two strings are said to be a permutation of each other when eit...read more
You are given a matrix of size N * M. Can you count the number of squares in it?
As the count will be very large, so compute it with modulo 10^9 + 7.
For Example:
Let N = 3 and M = 5 The number of ...read more
You have been given a binary tree of 'N' nodes. Print the Spiral Order traversal of this binary tree.
For example
For the given binary tree [1, 2, 3, -1, -1, 4, 5, -1, -1,...read more
You are provided with a Binary Search Tree (BST), all you have to do is to convert it into the sorted doubly linked list (DLL).
For Example:
Consider the above BST, it will be converted into t...read more
Q69. Which of the following numbers cannot be represented accurately in > binary? > a) 0.1 b) 6.5 c) 1/16 d)1.32 e) 0.590625 (not sure abt option e) > > 1. a only > 2. a and b > 3. a, b and d > 4. a, b and e > (not ...
read moreIdentifying which numbers cannot be accurately represented in binary.
Binary cannot accurately represent decimal fractions that do not have a power of 2 as their denominator.
Option a (0.1) and option e (0.590625) cannot be accurately represented in binary.
Option b (6.5) and option d (1.32) can be accurately represented in binary.
Option c (1/16) can be accurately represented in binary as 0.0001.
You are given a string ‘expression’ consists of characters ‘+’, ‘-’, ‘*’, ‘/’, ‘(‘, ‘)’ and ‘0’ to ‘9’, that represents an Arithmetic Expression in Infix Notation. Your task is t...read more
You are given two sorted arrays 'A' & 'B' of sizes 'N' & 'M'. You need to find the median of the two arrays when merged. If the total number of elements i.e., N + M is even then the m...read more
There is a one-dimensional garden of length 'N'. On each of the positions from 0 to 'N', there is a fountain, and this fountain’s water can reach up to a certain range as explained further. In ...read more
You are given two binary trees with 'N' and 'M' nodes respectively. You need to return true if the two trees are identical. Otherwise, return false.
Below is the example and explanation of Identi...read more
You have been given an array(ARR) of positive integers and an integer X. You have to find the minimum length subarray such that the sum of all of its elements is strictly grea...read more
You need to design a global auditorium booking platform, which could be booked from anywhere in the world. It can host multiple shows at once as it has 2 stages with different seating capacity. The...read more
You are given a two-dimensional array/list of integers consisting of 0s and 1s. In the list, 1 represents land and 0 represents water.
The task is to find the number of distinct islands where a ...read more
You are given the schedule of N meetings with their start time Start[i] and end time End[i]. But you have only 1 meeting room. So, you need to tell the meeting numbers you can organize in the gi...read more
You have been given a singly Linked List of 'N' nodes with integer data and an integer 'K'. Your task is to remove the Kth node from the end of the given Linked List.
Fo...read more
Given a singly linked list of integers. Your task is to return the head of the reversed linked list.
For example:
The given linked list is 1 -> 2 -> 3 -> 4-> NULL. Then the reverse linked ...read more
Ninja requests a PS5 from Santa on Christmas. Santa decides to give Ninja a brand new PS5, but he locks it in a safe and gives Ninja a string SECRETCODE. The password to open the safe is the length...read more
Q81. What are the steps which you will follow if a customer calls and tell you that he is not able to do any editing in Microsoft word?
Steps to follow when a customer reports inability to edit in Microsoft Word
Ask the customer if they are receiving any error messages
Check if the document is in read-only mode
Check if the customer has the necessary permissions to edit the document
Check if the customer's version of Microsoft Word is up to date
Try repairing or reinstalling Microsoft Word
If all else fails, escalate the issue to a higher level of support
You are given the arrival and departure times of N trains at a railway station in a day. You need to find the minimum of platforms required for the railway station such that no ...read more
Ninja has to design a 2 players game Tic-Tac-Toe played on an ‘N’ * ‘N’ grid.
Ninja has to assume the following rules while playing the game:
This game is played between two people (Player 1 a...read more
You are given an infinite supply of coins of each of denominations D = {D0, D1, D2, D3, ...... Dn-1}. You need to figure out the total number of ways W, in which you can make a change fo...read more
Q85. You have 3 baskets- one containing apples, one oranges and the last containing both. All baskets are incorrectly labelled.You can pick *one* fruit from *any one* basket and are supposed to correctly label all o...
read morePick a fruit from the basket containing both fruits and label the baskets accordingly.
Pick a fruit from the basket labelled 'apples and oranges'
If you pick an apple, label the basket containing only apples
If you pick an orange, label the basket containing only oranges
Label the remaining basket as containing both fruits
You have been given a string ‘A’ consisting of lower case English letters. Your task is to find the length of the longest palindromic subsequence in ‘A’.
A subsequence is a sequen...read more
You are given two strings 'A' and 'B' where string 'A' is fixed. But you can perform left shift operations on string B any number of times.
Your task is to find out the minim...read more
You are given an array “arr'' of integers. Your task is to find the contiguous subarray within the array which has the largest product of its elements. You have to report this maximum pr...read more
Given two variables ‘X’ and ‘Y’. Your task is to swap the number without using a temporary variable or third variable.
Swap means the value of ‘X’ and ‘Y’ must be interchan...read more
You are given an integer 'N'. Your task is to count the number of integers between 1 and 'N' both inclusive which are coprime to 'N'.
Note:
Two numbers are coprime if their greatest common divisor(...read more
A binary tree is a tree where each node has at most two children i.e left child and right child.
You are given a binary tree, where the structure of the node is as follow -:
class Bin...read more
You have been given two arrays, 'AT' and 'DT', representing the arrival and departure times of all trains that reach a railway station.
Your task is to find the minimum number of plat...read more
You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to return the list of all pairs of elements such that each sum of elements of each pair equals 'S'.
Note:
Each pair shou...read more
Q94. A process doesn't require additional processors to carry out 40% of > it's execution since 40% is mostly sequential. Determine how many > additional processors are required to execute the process in 150s if > t...
read moreAdditional processors required to execute a process in 150s with 40% sequential execution.
Process takes 300s on a single processor
40% of the process is sequential and doesn't require additional processors
Calculate the time taken by the remaining 60% of the process
Determine the speedup required to execute the remaining 60% in 150s
Calculate the number of additional processors required based on the speedup
You are given an array 'ARR' of positive integers, each of which represents the number of liters of water in that particular bucket, we have to make the liters of water in every bucket equal.
We are allowe...read more
You are given a starting position for a rat which is stuck in a maze at an initial point (0, 0) (the maze can be thought of as a 2-dimensional plane). The maze would be given in the form of a squar...read more
You are given a string 'S' and you need to return the length of the longest duplicate substring in the given string. The occurrence of duplicate sub-strings can overlap also.
If there...read more
Q98. Given a string s[1...n] and a reverse function reverse(s, i, k) > which reverses the character sequence from i to k (inclusive of both) > in string s, determine what the following operations result in. > 1 > re...
read moreDetermining the result of string reversal and rotation operations using a reverse function.
The first operation reverses the first half and second operation reverses the second half of the string, resulting in a rotation of the string left k positions.
The third operation reverses the entire string, resulting in a reversal of the string.
Therefore, the correct answer is (b) Rotates the String left k positions.
Example: s = 'abcdefg', k = 3, reverse(s, 1, 3) = 'cbadefg', reverse(s...read more
Q99. Given a string of containing lower case letters and upper case characters. Find the number of occurrences of each character. The question was further modified to include the special characters as well. I was as...
read moreCount the occurrences of each character in a given string including special characters.
Create test cases for empty string
Test for string with only one character
Test for string with all characters being the same
Test for string with all characters being different
Test for string with special characters
Ninja is an avid story lover. Today, he decides to go to the famous Storyteller of Ninjaland to listen to new stories. The Storyteller takes 'Y' coins to tell one story. The Storytelle...read more
More about working at Microsoft Corporation
Top HR Questions asked in null
Interview Process at null
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month