Microsoft Coding Interview Questions

Review this list of 20 Microsoft coding software engineer interview questions and answers verified by hiring managers and candidates.
  • "Sorted the array and stored the minimum difference in a variable and then traversed the array for the pairs having minimum difference"

    Aashka C. - "Sorted the array and stored the minimum difference in a variable and then traversed the array for the pairs having minimum difference"See full answer

    Software Engineer
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 

    "int reverse(int x) { int rev = 0; bool isNegative = false; if(x 0){ int r = x % 10; rev = rev * 10 + r; x = x / 10; } if(isNegative){ return -rev; } return rev; } `"

    Nilay B. - "int reverse(int x) { int rev = 0; bool isNegative = false; if(x 0){ int r = x % 10; rev = rev * 10 + r; x = x / 10; } if(isNegative){ return -rev; } return rev; } `"See full answer

    Software Engineer
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 
    +16

    "We can use dictionary to store cache items so that our read / write operations will be O(1). Each time we read or update an existing record, we have to ensure the item is moved to the back of the cache. This will allow us to evict the first item in the cache whenever the cache is full and we need to add new records also making our eviction O(1) Instead of normal dictionary, we will use ordered dictionary to store cache items. This will allow us to efficiently move items to back of the cache a"

    Alfred O. - "We can use dictionary to store cache items so that our read / write operations will be O(1). Each time we read or update an existing record, we have to ensure the item is moved to the back of the cache. This will allow us to evict the first item in the cache whenever the cache is full and we need to add new records also making our eviction O(1) Instead of normal dictionary, we will use ordered dictionary to store cache items. This will allow us to efficiently move items to back of the cache a"See full answer

    Software Engineer
    Coding
    +6 more
  • Microsoft logoAsked at Microsoft 
    +1

    "#simple solution 1.firstly find the node in the bst (O(logn) time complexity it take) 2.now removing the node consists of 3 cases: 1.if the node is leaf (no children): (keep track of parent and do) parent.left or parent.right=NULL simply remove the node () 2.if(has one child) replace the node with its child 3.if has both childs we replace the node with either inorder predesor(max of left tree)or inorder succesor and remove the node wh"

    Sambangi C. - "#simple solution 1.firstly find the node in the bst (O(logn) time complexity it take) 2.now removing the node consists of 3 cases: 1.if the node is leaf (no children): (keep track of parent and do) parent.left or parent.right=NULL simply remove the node () 2.if(has one child) replace the node with its child 3.if has both childs we replace the node with either inorder predesor(max of left tree)or inorder succesor and remove the node wh"See full answer

    Software Engineer
    Coding
  • Microsoft logoAsked at Microsoft 
    +10

    "we can use two pointer + set like maintain i,j and also insert jth character to set like while set size is equal to our window j-i+1 then maximize our answer and increase jth pointer till last index"

    Kishor J. - "we can use two pointer + set like maintain i,j and also insert jth character to set like while set size is equal to our window j-i+1 then maximize our answer and increase jth pointer till last index"See full answer

    Software Engineer
    Coding
    +4 more
  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • Microsoft logoAsked at Microsoft 
    +20

    "Idea for solution: Reverse the complete char array Reverse the words separated by space. i.e. Find the space characters and the reverse the subarray between two space characters. vector reverseSubarray(vector& arr, int s, int e) { while (s reverseWords(vector& arr ) { int n = arr.size(); reverse(arr, 0, n - 1"

    Rahul M. - "Idea for solution: Reverse the complete char array Reverse the words separated by space. i.e. Find the space characters and the reverse the subarray between two space characters. vector reverseSubarray(vector& arr, int s, int e) { while (s reverseWords(vector& arr ) { int n = arr.size(); reverse(arr, 0, n - 1"See full answer

    Software Engineer
    Coding
    +4 more
  • Microsoft logoAsked at Microsoft 

    "Abstract class A class that can have Abstract methods - without implementations and Concerete Methods i.e with implementation. Can have private, protected and public access modifiers. Supports Single inheritance i.e a class can extend only 1 abstract class Can have constructors Mainly used when sharing common behaviors Interface Class A collection of abstract methods ( can have static and default methods also - onwards of java 8) Public, static, final are the access"

    Sue G. - "Abstract class A class that can have Abstract methods - without implementations and Concerete Methods i.e with implementation. Can have private, protected and public access modifiers. Supports Single inheritance i.e a class can extend only 1 abstract class Can have constructors Mainly used when sharing common behaviors Interface Class A collection of abstract methods ( can have static and default methods also - onwards of java 8) Public, static, final are the access"See full answer

    Software Engineer
    Coding
    +2 more
  • Microsoft logoAsked at Microsoft 

    "Let me try to explain it with simple life analogy You're cooking dinner in the kitchen. Multithreading is when you've got a bunch of friends helping out. Each friend does a different job—like one chops veggies while another stirs a sauce. Everyone focuses on their task, and together, you all make the meal faster. In a computer, it's like different jobs happening all at once, making stuff happen quicker, just like having lots of friends helping makes dinner ready faster."

    Praveen D. - "Let me try to explain it with simple life analogy You're cooking dinner in the kitchen. Multithreading is when you've got a bunch of friends helping out. Each friend does a different job—like one chops veggies while another stirs a sauce. Everyone focuses on their task, and together, you all make the meal faster. In a computer, it's like different jobs happening all at once, making stuff happen quicker, just like having lots of friends helping makes dinner ready faster."See full answer

    Software Engineer
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 

    "First of all, stack and heap memory are abstraction on top of the hardware by the compiler. The hardware is not aware of stack and heap memory. There is only a single piece of memory that a program has access to. The compiler creates the concepts of stack and heap memory to run the programs efficiently. Programs use stack memory to store local variables and a few important register values such as frame pointer and return address for program counter. This makes it easier for the compiler to gene"

    Stanley Y. - "First of all, stack and heap memory are abstraction on top of the hardware by the compiler. The hardware is not aware of stack and heap memory. There is only a single piece of memory that a program has access to. The compiler creates the concepts of stack and heap memory to run the programs efficiently. Programs use stack memory to store local variables and a few important register values such as frame pointer and return address for program counter. This makes it easier for the compiler to gene"See full answer

    Software Engineer
    Coding
    +2 more
  • +1

    "Isn't adding and removing from a max heap logn so the time complexity of the second approach would be O((n+k)logn)."

    Abdullah J. - "Isn't adding and removing from a max heap logn so the time complexity of the second approach would be O((n+k)logn)."See full answer

    Software Engineer
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 
    Video answer for 'Implement k-means clustering.'

    "i dont know"

    Dinesh K. - "i dont know"See full answer

    Software Engineer
    Coding
    +5 more
  • Microsoft logoAsked at Microsoft 
    Video answer for 'Product of Array Except Self'
    +41

    "If 0's aren't a concern, couldn't we just multiply all numbers. and then divide product by each number in the list ? if there's more than one zero, then we just return an array of 0s if there's one zero, then we just replace 0 with product and rest 0s. what am i missing?"

    Sachin R. - "If 0's aren't a concern, couldn't we just multiply all numbers. and then divide product by each number in the list ? if there's more than one zero, then we just return an array of 0s if there's one zero, then we just replace 0 with product and rest 0s. what am i missing?"See full answer

    Software Engineer
    Coding
    +3 more
  • Microsoft logoAsked at Microsoft 

    "Was the statement very similar to the leetcode or was it changed and only the main idea remained?"

    Anonymous Wombat - "Was the statement very similar to the leetcode or was it changed and only the main idea remained?"See full answer

    Software Engineer
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 

    "You are given a string S and a number K as input, and your task is to print S to console output considering that, at most, you can print K characters per line. Example: S = "abracadabra sample" K = 11 Output: abracadabra sample Note that this problem requires the interviewee gather extra requirements from the interviewer (e.g. do we care about multiple white spaces? what if the length of a word is greater than K, ...)"

    B. T. - "You are given a string S and a number K as input, and your task is to print S to console output considering that, at most, you can print K characters per line. Example: S = "abracadabra sample" K = 11 Output: abracadabra sample Note that this problem requires the interviewee gather extra requirements from the interviewer (e.g. do we care about multiple white spaces? what if the length of a word is greater than K, ...)"See full answer

    Software Engineer
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 
    Video answer for 'Find the number of rotations in a circularly sorted array.'
    +8

    "from typing import List def find_rotations(nums: List[int]) -> int: left = 0 right = len(nums) - 1 if len(nums) < 2 or nums[left] < nums[right]: return 0 while(left + 1 < right): mid = left + (right - left) // 2 if nums[mid] < nums[left]: right = mid else: left = mid return left + 1 `"

    Aikya S. - "from typing import List def find_rotations(nums: List[int]) -> int: left = 0 right = len(nums) - 1 if len(nums) < 2 or nums[left] < nums[right]: return 0 while(left + 1 < right): mid = left + (right - left) // 2 if nums[mid] < nums[left]: right = mid else: left = mid return left + 1 `"See full answer

    Software Engineer
    Coding
    +1 more
  • "Example: bucket A: 3 liters capacity bucket B: 5 liters capacity goal: 4 liters You are asked to print the logical sequence to get to the 4 liters of water in one bucket. Follow up: How would you solve the problem if you have more than 2 buckets of water?"

    B. T. - "Example: bucket A: 3 liters capacity bucket B: 5 liters capacity goal: 4 liters You are asked to print the logical sequence to get to the 4 liters of water in one bucket. Follow up: How would you solve the problem if you have more than 2 buckets of water?"See full answer

    Software Engineer
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 

    "Leetcode 347: Heap + Hashtable Follow up question: create heap with the length of K instead of N (more time complexity but less space )"

    Chen J. - "Leetcode 347: Heap + Hashtable Follow up question: create heap with the length of K instead of N (more time complexity but less space )"See full answer

    Software Engineer
    Coding
    +3 more
  • Microsoft logoAsked at Microsoft 
    Software Engineer
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 
    Software Engineer
    Coding
    +1 more
Showing 1-20 of 20