
Microsoft Corporation


50+ Microsoft Corporation Software Engineer Interview Questions and Answers
Q1. 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.
Q2. Word Wrap Problem Statement
You are tasked with arranging 'N' words of varying lengths such that each line contains at most 'M' characters, with each word separated by a space. The challenge is to minimize the ...read more
The goal is to minimize the total cost of arranging 'N' words on each line with a maximum character limit 'M'.
Calculate the cost of each line as the cube of extra space characters needed to reach 'M'.
Minimize the total cost by arranging words to fit within the character limit on each line.
Ensure each word appears fully on one line without breaking across lines.
Q3. Distinct Islands Problem Statement
Given a two-dimensional array/list consisting of integers 0s and 1s, where 1 represents land and 0 represents water, determine the number of distinct islands. A group of conne...read more
Count the number of distinct islands in a 2D array of 0s and 1s.
Identify islands by performing depth-first search (DFS) on the grid
Use a set to store the shape of each island and check for duplicates
Consider translations to determine distinct islands
Design a system similar to Red Bus for handling bookings and onboarding vendors and customers.
Implement a user-friendly interface for customers to search and book tickets
Create a vendor portal for vendors to manage their offerings and availability
Include payment gateway integration for secure transactions
Develop a robust backend system for managing bookings, cancellations, and refunds
Utilize a database to store user information, booking details, and vendor listings
Q5. Testing whether every left child's value is less than the right child's value in a binary tree
To test if every left child's value is less than the right child's value in a binary tree.
Traverse the binary tree using any traversal algorithm (e.g., in-order, pre-order, post-order)
Compare the value of each left child with its right child
If any left child's value is greater than or equal to its right child's value, return false
If all left child's values are less than their right child's values, return true
Q6. On circular queue and finding the last number which is highest and contains same number. Of digits a the given numbber
The question is about finding the last number in a circular queue that has the highest number of digits.
Implement a circular queue data structure
Iterate through the circular queue to find the last number with the highest number of digits
Compare the number of digits of each number in the circular queue
Keep track of the last number with the highest number of digits
Q7. Write a program to store a tree on a file. Also write code to reconstruct the tree from that file. Think of efficient techniques
Program to store and reconstruct a tree from a file with efficient techniques.
Use a recursive approach to traverse the tree and write each node to the file
Include information about the node's parent and children in the file
Use a unique identifier for each node to reconstruct the tree from the file
Use a data structure like a hash table to store the nodes and their identifiers for efficient reconstruction
Q8. Given an array, find how many such pairs having sum equal to 0 are there?
Find pairs in an array with sum equal to 0.
Use a hash table to store the frequency of each element.
Iterate through the array and for each element, check if its complement (negative value) exists in the hash table.
If it exists, add the frequency of the complement to the count of pairs.
Return the count of pairs.
Example: array = [2, -2, 3, 0, -3], pairs = 2 (-2, 2 and -3, 3)
Q9. Given a string of unknown length, what is a good approach to find n-k th element from last
To find n-k th element from last in a string of unknown length
Traverse the string to find its length
Calculate the position of n-k th element from last
Traverse the string again to find the element at calculated position
Q10. You have a Binary tree having numbers>=0 and a numeber N. Print all downwards paths from any node having the sum of elements equal to N
Print all downward paths from any node in a binary tree with sum of elements equal to N.
Traverse the binary tree and keep track of the sum of elements in the path from root to current node.
If the sum equals N, print the path from root to current node.
Recursively traverse the left and right subtrees with updated sum.
Use a stack to keep track of the current path being traversed.
Example: Binary tree with root 1, left child 2, right child 3, and N=3. Output: [1,2], [1,3].
Q11. Why important in learning programming languages.
Learning programming languages is important for software engineers to effectively communicate with computers and develop software solutions.
Programming languages are the foundation of software development.
Learning multiple languages expands the range of problems a software engineer can solve.
Different languages have different strengths and are suited for different tasks.
Knowing multiple languages improves adaptability and flexibility in the industry.
Programming languages evol...read more
Q12. What do you know about Object Oriented Programming?
Object Oriented Programming is a programming paradigm based on the concept of objects, which can contain data and code.
OOP focuses on creating objects that interact with each other to solve problems
Encapsulation, inheritance, and polymorphism are key principles of OOP
Examples of OOP languages include Java, C++, and Python
Q13. Finding a loop in a directed graph, find the last element in a binary tree
To find a loop in a directed graph, use Floyd's cycle-finding algorithm. To find the last element in a binary tree, traverse the tree and return the rightmost leaf node.
For finding a loop in a directed graph, use Floyd's cycle-finding algorithm which uses two pointers moving at different speeds.
To find the last element in a binary tree, traverse the tree recursively or iteratively and return the rightmost leaf node.
Q14. Write the backend server code for a tic tac toe game
Backend server code for a tic tac toe game
Create a RESTful API using a framework like Express.js
Implement game logic to check for winning conditions
Use a database to store game state and user information
Handle user authentication and authorization
Implement real-time updates using WebSockets
Q15. Rearranging a string so no consecutive characters are the same
Rearrange a string to avoid consecutive same characters.
Iterate through the string and keep track of the previous character.
If the current character is the same as the previous, swap it with the next different character.
Repeat until no consecutive same characters are left.
Q16. Given an array of strings, count the number of unique occurrences
Count the number of unique occurrences in an array of strings.
Create a hash table to store the count of each string occurrence.
Iterate through the array and update the count in the hash table.
Count the number of unique occurrences by counting the number of keys in the hash table.
Q17. Find the shortest path in a graph between 2 given vertices.
Use Dijkstra's algorithm to find the shortest path between 2 vertices in a graph.
Implement Dijkstra's algorithm to find the shortest path
Create a priority queue to keep track of the vertices with the shortest distance
Use a visited set to avoid revisiting vertices
Stop when the destination vertex is reached
Return the shortest path found
Example: finding the shortest path between A and D in a graph with weighted edges: A->B(1), A->C(4), B->D(3), C->D(2) returns [A, B, D]
Q18. Finding the nth character in a stream of bytes
To find the nth character in a stream of bytes, we need to read the stream byte by byte until we reach the nth position.
Start reading the stream byte by byte until you reach the nth position
Return the byte at the nth position
If the stream ends before reaching the nth position, return null or throw an exception
Q19. Design LLD of a top K frequently purchased items in a amazon/flipkart sale
Design a system to find top K frequently purchased items in a sale on e-commerce platforms like Amazon or Flipkart.
Use a data structure like a hashmap to store item frequencies
Implement a priority queue to keep track of top K items based on frequency
Update the priority queue whenever a new item is purchased
Consider using a heap data structure for efficient retrieval of top K items
Q20. Deep copy a singly linked list with next and a random pointer
Deep copy a singly linked list with next and a random pointer
Create a new node for each node in the original list
Copy the next and random pointers of each node to the new node
Use a hash table to keep track of original and new nodes
Q21. Leetcode: Find centre of a linked list, follow-up: find intersection of two linked lists.
To find the intersection of two linked lists, first find the lengths of both lists and then align the starting points before iterating to find the intersection node.
Find the lengths of both linked lists.
Align the starting points of both lists by moving the pointer of the longer list by the difference in lengths.
Iterate through both lists simultaneously and compare nodes to find the intersection node.
Q22. Syetem Design. Design a file upload and download system
Design a file upload and download system for efficient file management.
Use a cloud storage service like AWS S3 for storing files securely.
Implement a user-friendly interface for users to easily upload and download files.
Include features like file versioning, access control, and encryption for data security.
Consider implementing a queuing system for handling large file uploads to prevent system overload.
Use a content delivery network (CDN) for faster file downloads.
Implement m...read more
Q23. What is operator nd there function?
The '&&' operator is a logical AND operator that returns true if both operands are true, otherwise false.
Used to combine two boolean expressions and return true only if both are true
Short-circuits if the first operand is false, not evaluating the second operand
Example: if(x > 5 && y < 10) { // do something }
Q24. Variation of aggressive cows problem (requires binary search)
Use binary search to find the minimum distance to escape aggressive cows in a field.
Implement a function to check if cows can be placed with a minimum distance in a field.
Use binary search to find the minimum distance that satisfies the condition.
Keep track of the maximum distance found so far while performing binary search.
Q25. Which os system used in computer ?
There are several operating systems used in computers, including Windows, macOS, and Linux.
Windows is the most widely used OS for personal computers.
macOS is the OS used in Apple computers.
Linux is an open-source OS used in servers and some personal computers.
Other OS include Chrome OS, FreeBSD, and Solaris.
Q26. What is the relation of msecxel and powerbi
Power BI is a business analytics tool by Microsoft while Excel is a spreadsheet program. Power BI can connect to Excel files for data analysis.
Power BI is a business analytics tool by Microsoft
Excel is a spreadsheet program also by Microsoft
Power BI can connect to Excel files for data analysis
Q27. how to scale to billions of user
To scale to billions of users, focus on horizontal scaling, efficient database design, caching, load balancing, and microservices architecture.
Implement horizontal scaling by adding more servers to distribute the load.
Optimize database design for efficient read and write operations, consider sharding or partitioning.
Utilize caching mechanisms like Redis or Memcached to reduce database load.
Implement load balancing to evenly distribute incoming traffic across multiple servers....read more
Q28. Finding the next highest palindrome
The task is to find the next highest palindrome number given a number.
Convert the given number to a string
Check if the number is already a palindrome
If not, increment the number by 1 and check if it is a palindrome
Repeat the previous step until a palindrome is found
Q29. Cloning a linked list-like structure
Cloning a linked list-like structure
Create a new node for each node in the original linked list
Set the value of the new node to the value of the corresponding node in the original linked list
Set the next pointer of the new node to the new node corresponding to the next node in the original linked list
Repeat the above steps until all nodes in the original linked list are cloned
Q30. To canonicalize a directory path
Canonicalizing a directory path involves simplifying and standardizing the path to remove any redundant or unnecessary elements.
Remove any consecutive slashes and replace them with a single slash
Remove any trailing slashes
Resolve any relative paths (e.g., '..' and '.')
Handle special cases like the root directory ('/')
Normalize the path by removing any unnecessary elements
Q31. Given an array find the given element in the array
Use linear search algorithm to find the given element in the array of strings.
Iterate through the array and compare each element with the given element
Return the index if found, otherwise return -1
Time complexity is O(n) where n is the number of elements in the array
Q32. What is algorithm? How to use?
An algorithm is a step-by-step procedure for solving a problem or accomplishing a task.
An algorithm is a set of instructions that specifies a sequence of operations to be performed.
Algorithms can be used to solve mathematical problems, data processing tasks, and more.
Examples of algorithms include sorting algorithms like bubble sort and searching algorithms like binary search.
Q33. What is array?nd types?
An array is a data structure that stores a collection of elements of the same type in a contiguous memory location.
Arrays can be of different types such as integer arrays, float arrays, character arrays, etc.
An array of strings is a collection of strings stored in a contiguous memory location.
Example: string[] names = {"Alice", "Bob", "Charlie"};
Q34. Write code for Circular Linkekd List
Code for Circular Linked List implementation
Create a Node class with data and next pointer
Implement methods for insertion, deletion, and traversal
Ensure the last node points back to the first node to form a circular structure
Q35. Run length encoding of a string.
Run length encoding is a simple form of data compression where consecutive characters are replaced with a single character and a count.
Iterate through the input string and count consecutive characters.
Replace consecutive characters with a single character and a count.
Return the encoded string.
Q36. Convert doubly linked list to BST
Convert a doubly linked list to a binary search tree.
Find the middle node of the linked list.
Make it the root of the BST.
Recursively convert the left and right halves of the list to the left and right subtrees of the root.
Use the doubly linked list to traverse the list efficiently.
Q37. Which language ur perfect
I am proficient in multiple languages, including Java, Python, and C++.
Proficient in Java, Python, and C++
Experience with web development languages like JavaScript and HTML/CSS
Familiarity with scripting languages like Bash and PowerShell
Q38. how to handle offline users
Handle offline users by implementing offline mode functionality and syncing data when connection is restored.
Implement offline mode functionality to allow users to access certain features offline.
Store user data locally on the device and sync with the server when connection is available.
Provide feedback to users about their offline status and guide them on how to sync data.
Use caching mechanisms to store data temporarily and update it when connection is restored.
Q39. Project explanation and run the project
I will explain and demonstrate the project.
I will provide a brief overview of the project's purpose and goals.
I will explain the technologies and tools used in the project.
I will describe the project's architecture and components.
I will demonstrate the project by running it and showcasing its features.
I will answer any specific questions or concerns about the project.
Q40. Leetcode: Interval merging problem
Merge overlapping intervals in an array
Sort the intervals based on the start time
Iterate through the intervals and merge overlapping ones
Update the end time of the merged interval
Q41. Design recommendation system for ecommerce
Design a recommendation system for ecommerce
Utilize collaborative filtering to recommend products based on user behavior
Implement content-based filtering to suggest items similar to those previously purchased
Incorporate machine learning algorithms to personalize recommendations
Consider using a hybrid approach combining collaborative and content-based filtering
Include user feedback and ratings to improve recommendation accuracy
Q42. Analysis about app performance
App performance analysis involves identifying and resolving bottlenecks to improve user experience.
Collect and analyze performance metrics such as response time, CPU usage, memory usage, and network latency.
Identify and prioritize bottlenecks based on impact on user experience and frequency of occurrence.
Implement optimizations such as caching, code refactoring, and database tuning.
Continuously monitor and test performance to ensure improvements are effective.
Use tools such a...read more
Q43. Full form of RAM and ROM?
RAM stands for Random Access Memory and ROM stands for Read Only Memory.
RAM is a type of computer memory that can be accessed randomly, meaning any byte of memory can be accessed without touching the preceding bytes.
ROM is a type of memory that can only be read and not written to. It is used to store permanent data that cannot be changed.
Examples of RAM include DDR, DDR2, DDR3, and DDR4.
Examples of ROM include PROM, EPROM, EEPROM, and flash memory.
Q44. implement serialization of tree
Serialize a tree data structure
Use pre-order traversal to serialize the tree
Store null values as a special character
Use a delimiter to separate nodes
Example: 1,2,null,null,3,4,null,null,5,null,null
Deserialize by splitting the string and using a queue
Q45. Number of connected components.
Number of connected components in a graph represent the number of subgraphs that are not connected to each other.
Use depth-first search (DFS) or breadth-first search (BFS) to find connected components.
Count the number of times DFS or BFS is called to find the number of connected components.
Example: In a graph with 3 connected components, the answer would be 3.
Q46. implement stack using linkedlist
Implementing stack using linked list
Create a Node class with data and next pointer
Create a Stack class with top pointer
Implement push() method to add element to top of stack
Implement pop() method to remove element from top of stack
Implement peek() method to return top element without removing it
Q47. Design phone book(Trie)
Phone book design using Trie data structure
Implement Trie data structure to store phone numbers
Each node in the Trie represents a digit in the phone number
Use Trie to efficiently search for phone numbers based on prefixes
Q48. Design a library management system
A library management system to track books, users, and transactions
Create database tables for books, users, transactions
Implement functions for adding, updating, and deleting books
Allow users to check out and return books
Generate reports on book availability and user activity
Q49. variation of 2 sum problem
Find two numbers in an array that add up to a target sum.
Use a hash map to store the difference between the target sum and each element.
Iterate through the array and check if the current element's complement exists in the hash map.
Return the indices of the two numbers that add up to the target sum.
Q50. Sort the array in alternates
Sort the array in alternates
Iterate through the array and separate the strings into two separate arrays based on their index being even or odd
Sort both arrays separately
Merge the two sorted arrays back into the original array in alternate positions
Q51. Design Auto completion.
Auto completion feature suggests possible completions as user types.
Implement a trie data structure to store all possible words in the dictionary.
As user types, traverse the trie to find all words that match the prefix.
Display the matched words in a dropdown menu for user selection.
Q52. implement priority queue
Priority queue is a data structure that stores elements with priority levels and retrieves them in order of priority.
Elements are added with a priority level and retrieved in order of priority
Can be implemented using a heap data structure
Operations include insert, delete, and peek
Can be used in algorithms such as Dijkstra's shortest path algorithm
Q53. Discuss monitoring techniques
Monitoring techniques are essential for tracking the performance and health of software systems.
Use logging to record events and errors in the system
Implement metrics to measure key performance indicators
Set up alerts to notify of any abnormal behavior
Utilize tracing to track requests and identify bottlenecks
Q54. Minimum path sum problem
Minimum path sum problem involves finding the path with the smallest sum in a grid of numbers.
Start from the top left corner and move only right or down.
Use dynamic programming to store the minimum sum at each cell.
The final cell will contain the minimum path sum.
Q55. design a rest API
Design a REST API for a software engineer interview
Define the resources and endpoints
Use HTTP methods for CRUD operations (GET, POST, PUT, DELETE)
Implement authentication and authorization
Use JSON for data exchange format
Include error handling and status codes
Q56. Turn BST into LL
Convert a Binary Search Tree (BST) into a sorted linked list (LL)
Perform in-order traversal of the BST and store the nodes in a list
Iterate through the list and create a new linked list with the nodes in sorted order
Q57. DSA qn on graphs
Graphs are data structures that consist of nodes and edges connecting them.
Graphs can be directed or undirected.
Common graph traversal algorithms include BFS and DFS.
Examples of graphs include social networks, road networks, and computer networks.
More about working at Microsoft Corporation




Top HR Questions asked in Microsoft Corporation Software Engineer
Interview Process at Microsoft Corporation Software Engineer

Top Software Engineer Interview Questions from Similar Companies








Reviews
Interviews
Salaries
Users/Month

