Microsoft | SDE | OA
Anonymous User
7968

Duration: 75 minutes

Task 1 Solution

import java.util.*;

class Solution {
    public int solution(int[] blocks) {
        int n = blocks.length;
        int[] farRight = new int[n];
        int farR = n - 1;

        for (int i = n - 1; i >= 0; i--) {
            if (i + 1 < n && blocks[i] > blocks[i + 1]) {
                farR = i;
            }
            farRight[i] = farR;
        }

        int farLeft = 0;
        int ans = 0;

        for (int i = 0; i < n; i++) {
            if (i - 1 >= 0 && blocks[i - 1] < blocks[i]) {
                farLeft = i;
            }
            ans = Math.max(ans, farRight[i] - farLeft + 1);
        }

        return ans;
    }
}

Task 2 Solution

import java.math.BigInteger;

class Solution {
    public int solution(String S) {
        BigInteger num = new BigInteger(S, 2);
        BigInteger two = new BigInteger("2");
        
        int countSteps = 0;
        
        while (!num.equals(BigInteger.ZERO)) {
            if (num.mod(two).equals(BigInteger.ZERO)) {
                num = num.divide(two);
            } else {
                num = num.subtract(BigInteger.ONE);
            }
            countSteps++;
        }
        
        return countSteps;
    }
}

Didn't passed all the test cases for this problem

Got call from recruiter
You can read the process in this post -> https://leetcode.com/discuss/interview-experience/6389446/microsoft-sde-l60/2859115

Comments (18)