title-img


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 →

Shortest Cycle Containing Target Node - Google Top Interview Questions

You are given a two-dimensional list of integers graph representing a directed graph as an adjacency list. You are also given an integer target. Return the length of a shortest cycle that contains target. If a solution does not exist, return -1. Constraints n, m ≤ 250 where n and m are the number of rows and columns in graph Example 1 Input Visualize graph = [ [1], [2], [0] ] target = 0 Output 3 Explanation The nodes 0 -> 1 -> 2

View Solution →