Sublist with Largest Min-Length Product - Google Top Interview Questions
You are given a list of integers nums and an integer pos. Find a sublist A of nums that includes the index (0-indexed) pos such that min(A) * A.length is maximized and return the value. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [-1, 1, 4, 3] pos = 3 Output 6 Explanation The best sublist is [4, 3]. Since min(4, 3) = 3 and its length is 2 we have 3 * 2 = 6.
View Solution →Sum of Sublist Range Sum - Google Top Interview Questions
You are given a list of non-negative integers nums and integers i and j. Let A be a sorted list of the sum of every sublist of nums. Return the sum of A from [i, j], inclusive. Constraints 1 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 2, 3, 4] i = 2 j = 3 Output 6 Explanation A = [1, 2, 3, 3, 4, 5, 6, 7, 9, 10] here and sum([3, 3]) = 6.
View Solution →Toggle Bitwise Expression - Google Top Interview Questions
You are given a string s representing a bitwise expression with the following characters: "0", "1", "&", "|", "(", and ")". In one operation, you can: Toggle "0" to "1" Toggle "1" to "0" Change "&" to "|" Change "|" to "&" Return the minimum number of operations required to toggle the value of the expression. Note: the precedence of the operators don't matter, since they'll be wrapped in brackets when necessary. For example, "1&0" and "1&(0&1)" are possible input
View Solution →Turn Into Non-Increasing List - Google Top Interview Questions
You are given a list of integers nums. Consider an operation where we take two consecutive integers and merge it into one by taking their sum. Return the minimum number of operations required so that the list becomes non-increasing. Constraints n ≤ 1,000 where n is the length of nums. Example 1 Input nums = [1, 5, 3, 9, 1] Output 2 Explanation We can merge [1, 5] to get [6, 3, 9, 1] and then merge [6, 3] to get [9, 9, 1]. Example 2 Input nums = [3]
View Solution →Towers Without a Valley - Google Top Interview Questions
You are given a list of integers nums. Consider a list of integers A such that A[i] ≤ nums[i]. Also, there are no j and k such that there exist j < i < k and A[j] > A[i] and A[i] < A[k]. Return the maximum possible sum of A. Constraints 1 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [10, 6, 8] Output 22 Explanation We can create A = [10, 6, 6]. Example 2 Input nums = [4, 5, 1, 1, 5] Output 12 Explanation We can create A
View Solution →