title-img


Incrementable Stack - Microsoft Top Interview Questions

Implement a stack with the following methods: IncrementableStack() constructs a new instance of an incrementable stack append(int val) appends val to the stack pop() pops and returns the last element in the stack increment(int inc, inc count) increments the value of bottom count elements by inc Each method should be done in \mathcal{O}(1)O(1) time. You can assume that for pop, the stack is non-empty when it is called. Constraints n ≤ 100,000 where n is the number o

View Solution →

Bus Stop - Microsoft Top Interview Questions

You are given a list of integers nums representing bus stops on a line where nums[i] represents the time a bus must arrive at stop i. Given that buses can only move forward, return the minimum number of buses that are needed to pass through all the stops. Constraints n ≤ 1,000 where n is length of nums. Example 1 Input nums = [1, 2, 7, 9, 3, 4] Output 2 Explanation One bus can take this route [1, 2, 3, 4] and another can do [7, 9]. Example 2 Input nums

View Solution →

Bulk Shift Letters - Microsoft Top Interview Questions

You are given a lowercase alphabet string s and a list of integers shifts. Each element shifts[i] means to shift the first i + 1 letters of s by shifts[i] positions. Shifting a letter should wrap over "z" to "a". For example, shifting “z” by 2 results in “b”. Return the resulting string after applying shifts to s. Constraints 1 ≤ n ≤ 100,000 where n is the length of s and shifts Example 1 Input s = "afz" shifts = [1, 2, 1] Output "eia" Explanation We shif

View Solution →

Beer Bottles - Microsoft Top Interview Questions

You are given an integer n representing n full beer bottles. Given that you can exchange 3 empty beer bottles for 1 full beer bottle, return the number of beer bottles you can drink. Constraints 0 ≤ n < 2 ** 31 Example 1 Input n = 9 Output 13 Explanation In first round, we drink 9 beer bottles. We can exchange the 9 empty ones for 3 beer bottles. We can exchange the 3 empty ones for 1 beer bottle.

View Solution →

Split List - Microsoft Top Interview Questions

Given a list of integers nums, return whether you can partition the list into two non-empty sublists such that every number in the left sublist is strictly less than every number in the right sublist. Constraints n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [5, 3, 2, 7, 9] Output True Explanation We can split the list into left = [5, 3, 2] and right = [7, 9]

View Solution →