title-img


Maximize the Number of Equivalent Pairs After Swaps - Google Top Interview Questions

You are given a list of integers of the same length A and B. You are also given a two-dimensional list of integers C where each element is of the form [i, j] which means that you can swap A[i] and A[j] as many times as you want. Return the maximum number of pairs where A[i] = B[i] after the swapping. Constraints n ≤ 100,000 where n is the length of A and B m ≤ 100,000 where m is the length of C Example 1 Input A = [1, 2, 3, 4] B = [2, 1, 4, 3] C = [ [0, 1],

View Solution →

Maximum Product Path in Matrix - Google Top Interview Questions

You are given a two-dimensional list of integers matrix. You are currently at the top left corner and want to move to the bottom right corner. In each move, you can move down or right. Return the maximum product of the cells visited by going to the bottom right cell. If the result is negative, return -1. Otherwise, mod the result by 10 ** 9 + 7. Constraints 1 ≤ n, m ≤ 20 where n and m are the number of rows and columns in matrix -2 ≤ matrix[r][c] ≤ 2 Example 1 Input

View Solution →

Max Multiplied Pairings Sequel - Google Top Interview Questions

You are given two lists of integers nums and multipliers. For each i = 0 to i = multiplers.length - 1, inclusive, perform the following operation: Remove one integer e from either the beginning or the end of nums Add multipliers[i] * e to your running total Return the maximum total possible after performing the operations. Constraints 0 ≤ m ≤ n ≤ 1,000 where n is the length of nums and m is the length of multipliers Example 1 Input nums = [5, 2, -7] multipliers = [2, 4, -

View Solution →

Minimum Time to Finish K Tasks - Google Top Interview Questions

You are given a two-dimensional list of integers tasks where each element has 3 integers. You are also given an integer k. Pick k rows from tasks, call it S, such that the following sum is minimized and return the sum: max(S[0][0], S[1][0], ...S[k - 1][0]) + max(S[0][1], S[1][1], ...S[k - 1][1]) + max(S[0][2], S[1][2], ...S[k - 1][2]) In other words, each of the 3 columns contribute to a cost, and is calculated by taking the max value of that column in S. The max of an empty li

View Solution →

Min Max Sets - Google Top Interview Questions

Given list of integers nums and integer k, return the number of non-empty subsets S such that min(S) + max(S) ≤ k. Note: For this problem, the subsets are multisets. That is, there can be duplicate values in the subsets since they refer to specific elements of the list, not values. Constraints 0 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 1, 4, 5] k = 5 Output 6 Explanation We can make the following subsets: [1], [1], [1, 1], [1, 4], [1

View Solution →