Recover Original List From Subsequences - Google Top Interview Questions
Given a two-dimensional list of integers lists, where each list is a subsequence of an original list, return the original list. The original list contains unique numbers. There is guaranteed to be one unique solution. Constraints n * m ≤ 100,000 where n and m are the number of rows and columns in lists Example 1 Input lists = [ [1, 3], [2, 3], [1, 2] ] Output [1, 2, 3] Example 2 Input lists = [ [1, 2, 4], [2, 3, 4] ] O
View Solution →Remove Sublist to Reach Equilibrium - Google Top Interview Questions
Given a list of integers nums and an integer k, you can remove any sublist at most once from the list. Return the length of the longest resulting list such that the amount of numbers strictly less than k and strictly larger than k is the same. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [5, 9, 7, 8, 2, 4] k = 5 Output 5 Explanation If we remove the sublist [8] then we'd get [5, 9, 7, 2, 4] and there's two numbers [2, 4] that's sma
View Solution →Removing Enclosed Parentheses- Google Top Interview Questions
You are given a string s containing valid number of brackets "(", ")" and lowercase alphabet characters. Return the string after removing all outermost brackets that enclose the whole string. Constraints n ≤ 100,000 where n is the length of s Example 1 Input s = "(((abc)))" Output "abc" Explanation The three "((()))" brackets are outermost so we remove them. Example 2 Input s = "(((abc)))(d)" Output "(((abc)))(d)" Explanation There's no outermost
View Solution →Reverse Equivalent Pairs - Google Top Interview Questions
Consider a function rev(num) which reverses the digits of num. For example, rev(123) = 321 and rev(100) = 1. Given a list of positive integers nums, return the number of pairs (i, j) where i ≤ j and nums[i] + rev(nums[j]) = nums[j] + rev(nums[i]). Mod the result by 10 ** 9 + 7. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 20, 2, 11] Output 7 Explanation We can have the following pairs: 1 and 1 1 and 2 1 and 11 20 a
View Solution →Shortest Absolute Value Distance - Google Top Interview Questions
You are given a two-dimensional list of integers matrix. You can move up, left, right, down and each move from matrix[a][b] to matrix[c][d] costs abs(matrix[a][b] - matrix[c][d]). Return the minimum cost to move from the top left corner to the bottom right corner. Constraints 1 ≤ n * m ≤ 200,000 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1, 100, 1], [2, 5, 3], [1, 2, 3] ] Output 4 Explanation
View Solution →