Microsoft Interview Questions

In this article, we will discuss Microsoft interview questions and solutions.

Introduction

Microsoft is one of the most well-known software companies today, solving large-scale industrial real-world problems. The technology employed at Microsoft is cutting-edge, giving the engineers there the opportunity to put their skills to the test and work on these technologies to provide innovative solutions to a variety of real-world challenges.

So, if you are preparing for the Microsoft tech interview, this article will help you prepare by listing down the top Microsoft interview questions and solutions for freshers. So let’s just get started with the article.

Microsoft Interview Questions 

This section will see the top Microsoft interview questions and their answers. The Microsoft interview questions here are designed for freshers. 

Mainly the Microsoft interview questions are based on networking, OS, Data structures and Algorithms. Some important questions are listed below:

1. Define the LRU cache and what data structure can be used to implement it?

Solution: We are provided with the complete number of possible page references. The cache (or memory) size is also specified (The number of page frames that the cache can hold at a time). When the cache is completely full, and a new page is referenced that is not in the cache, the LRU caching mechanism removes the least recently used frame.

An LRU cache is implemented using two data structures.

= A doubly-linked list is used to implement the queue. The queue will have a maximum size equal to the number of frames available (cache size). The pages that have been used the most recently will be in the front end, while the pages that have been used the least recently will be near the back end.

= A hash with the page number as the key and the address of the queue node as the value.

2. How is a URL shortened?

Solution: In URL shortening, every lengthy URL has a unique key, which is the component after the top-level domain name. The key of https://tinyurl.com/m3q2xt, for example, is m3q2xt. The HTTP status 301 (Moved Permanently), 302 (Found), 307 (Temporary Redirect), or 308 (Temporary Redirect) might be included in the redirection instruction given to a browser (Permanent Redirect).

3. What scheduling algorithm will you use for designing an elevator system?

Solution: SCAN (Elevator) algorithm

In the SCAN disc scheduling algorithm, the head begins at one end of the disc and advances to the other, serving requests until it reaches the other end. The head is then rotated in the opposite way, and the process continues as the head scans back and forth to access the disc. As a result, this technique is sometimes referred to as the elevator algorithm. As a result, requests at the middle receive greater attention, while those arriving after the disc arm must wait.

4. How to delete a node in the doubly-linked list?

Solution: Algorithm to delete a node "delNode."

= If the node to delete is the head node, then change the head pointer to the next current head.

= if headnode == delNode then

=   headnode =  delNode.nextNode

= Set prev of next to delNode, if next to del exists.

= if delNode.nextNode != none

=    delNode.nextNode.previousNode = delNode.previousNode

= Set next of previous to delNode, if previous to delNode exists.

= if delNode.previousNode != none

=    delNode.previousNode.nextNode = delNode.next

5. What is a Pipe and when it is used?

Solution: A pipe is typically a connection between two or more interconnected processes. It is a message-passing mechanism that is used for inter-process communication. A pipe makes it simple to transport data, such as the output of one programme activity, to another programme process. It's useful when two processes desire to communicate in one direction, i.e. inter-process communication (IPC)

6. Write a programme for the below problem.

We are given an 'ARR' array having  'N' positive integers. Our task is to determine the size of the smallest subset and the maximum OR possible. 

Refer to Subset OR for practising this question.

Solution: The C++ Program for the above question is as follows. We solved it with the DP approach.

int OR(int data[], int n)

{

    int maxOR = 0;

    for (int i = 0; i n; ++i) {

        maxOR |= data[i];

    }

 

    return mOR;

}

 

// Calculate the size of minimum subset

int minSubset(int data[], int n, int maxOR)

{

    vectorvectorint count(n + 1, vectorint(maxOR + 1, 1e9));

   

    count[0][0] = 0;

 

    for (int i = 0; i n; i++) {

        for (int j = 0; j = maxOR; j++) {

            // Do not consider ith element.

            count[i + 1][j] = min(count[i + 1][j], count[i][j]);

 

            // Consider ith element.

            if (count[i][j] != 1e9) {

                count[i + 1][j | data[i]] = min(

                    count[i + 1][j | data[i]], count[i][j] + 1);

            }

        }

    }

 

    return count[n][maxOR];

}

  1. Write a program for the below question.

Given a 'n x n' matrix and a number 'num', find the position of 'num' in the matrix if found. Else, print "Not Found". Every column and row is sorted in increasing order in the Matrix.

Solution: The most optimized C++ code (Top Right Element Approach) for the above question is implemented below.

int search(int mat[][], int n, int x)

{

    if (n == 0)

        return -1;

   

    int smallest = mat[0][0], largest = mat[n - 1][n - 1];

    if (x smallest || x largest)

        return -1;

   

    // Set indexes for the top right element

    int i = 0, j = n - 1;

    while (i n j = 0)

    {

        if (mat[i][j] == x)

        {

            cout "Element found at "

                  i ", " j;

            return 1;

        }

        if (mat[i][j] x)

            j--;

        else

            i++;

    }

 

    cout "Not Found\";

    return 0;

}

  1. Given a JSON string, find the max depth of the string.

Solution: We can find the max depth of the JSON string with the below C++ code.

int maxDepth(String jsonWord) {


    int current= 0;

    int max = 0;


    for (int i = 0; i jsonWord.size(); i++) {

        if (jsonWord.charAt(i) == '{') {

            current++;

        

        } else {

            if (jsonWord.charAt(i) == '}') {

                if (current max) {

                    max = current;

                }

                current--;

            }

        }

    }

    // Return the maximum answer

    return max;

}

 

Conclusion

In this article, we have extensively discussed important Microsoft interview questions and their solutions. These Microsoft Interview questions are designed for the fresher's technical interview.


Akshay Sharma

6 Blog posts

Comments