## Unique Characters of Every Substring - Microsoft Top Interview Questions

Given a lowercase alphabet string s, return the sum of the number of characters that are unique in every substring of s. Mod the result by 10 ** 9 + 7. Constraints n ≤ 100,000 where n is the length of s Example 1 Input s = "aab" Output 6 Explanation Here are the substrings and their counts: "a" - 1 "a" - 1 "b" - 1 "aa" - 0 (since "a" is not unique) "ab" - 2 "aab" - 1 ("since "a" is not unique)

View Solution →## Minimum Removals to Make Mountain List - Microsoft Top Interview Questions

You are given a list of integers nums. Return the minimum number of elements we can remove from nums such that the list becomes a mountain list. A mountain list is a list that is first strictly increasing and then strictly decreasing. Each of the increasing and decreasing parts should be non-empty. You can assume that a solution exists. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 6, 5, 7, 4] Output 1 Explanation We can re

View Solution →## Maximum Stack - Microsoft Top Interview Questions

Implement a maximum stack with the following methods: MaximumStack() constructs a new instance of a maximum stack append(int val) appends val to the stack peek() retrieves the last element in the stack max() retrieves the maximum value in the stack pop() pops and returns the last element in the stack popmax() pops and returns the last occurrence of the maximum value in the stack You can assume that for peek, max, pop and popmax, the stack is non-empty when they are called.

View Solution →## Candy Race Taking Square Candies - Microsoft Top Interview Questions

You are given an integer n representing the number of candies. You are playing a game against a friend and in each round a player can take some positive, square number. A player that can't make a move loses. Given that you go first and everyone plays optimally, return whether you will win. Constraints 1 ≤ n ≤ 100,000 Example 1 Input n = 11 Output True Explanation First you can take 9 candies, leaving 2 candies. Then, your friend can only take 1 candy, leaving 1 ca

View Solution →## Binary Search Tree Typo - Microsoft Top Interview Questions

You are given a binary tree root which is almost a binary search tree except two nodes' values have been swapped. Return the original binary search tree. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [2, [5, null, null], [7, [1, null, null], [8, null, null]]] Output [2, [1, null, null], [7, [5, null, null], [8, null, null]]] Explanation We can swap 1 and 5. Example 2 Input root = [0, [1, null, null], null]

View Solution →