Number of Decrements to Reach Zero - Google Top Interview Questions
You are given an integer n. In one operation you can either Decrement n by one If n is even, decrement by n / 2 If n is divisible by 3, decrement by 2 * (n / 3) Return the minimum number of operations required to decrement n to zero. Constraints n ≤ 10 ** 9 Example 1 Input n = 15 Output 5 Explanation Since n = 15 is divisible by 3 we decrement by 10 = 2 * (15 / 3) to get 5. Then we decrement by one to get 4. Then we decrement by 2 since n is even.
View Solution →Package Matching - Google Top Interview Questions
You are given two-dimensional list of integers sales and buyers. Each element in sales contains [day, price] meaning that the package is only available for sale on that day for that price. Each element in buyers contains [payday, amount] meaning that the buyer has that amount of money to spend on payday and afterwards. Given that each buyer can buy at most one package, and each package can be sold to at most one person, return the maximum number of packages that can be bought. Cons
View Solution →Permutations to Generate Binary Search Tree - Google Top Interview Questions
You are given a list of unique integers nums. We can create a binary search tree by taking each number in order and inserting it to an initially null binary search tree. Return the number of permutations of nums from which we can generate the same binary search tree. Mod the result by 10 ** 9 + 7. You can assume that the binary search tree does no rebalancing. Constraints 0 ≤ n ≤ 1,000 where n is the length of nums Example 1 Input nums = [2, 1, 3] Output 1 Explanatio
View Solution →Race to Finish Line - Google Top Interview Questions
You are driving a car in a one-dimensional line and are currently at position = 0 with speed = 1. You can make one of two moves: Accelerate: position += speed and speed *= 2 Reverse: speed = -1 if speed > 0 otherwise speed = 1. Return the minimum number of moves it would take to reach target. Constraints 1 ≤ target ≤ 100,000 Example 1 Input target = 7 Output 3 Explanation We can accelerate 3 times to reach 7. 0 -> 1 -> 3 -> 7 Example 2 Input t
View Solution →Rank of a Matrix - Google Top Interview Questions
You are given a two-dimensional list of integers matrix. Return a new matrix A with the same dimensions such that each A[r][c] is the rank of matrix[r][c]. The ranks of any two elements a and b that are either on the same row or column are calculated by: rank(a) < rank(b) if a < b rank(a) > rank(b) if a > b rank(a) = rank(b) if a = b Ranks are greater than or equal to 1 but are as small as possible. Constraints 0 ≤ n, m ≤ 250 where n and m are the number of rows
View Solution →