title-img


K-Distinct Groups - Google Top Interview Questions

You are given a list of integers counts where counts[i] represents the number of items that exist of type i. You are also given an integer k. Return the maximum number of groups of size k we can have given that each group must have items of distinct types. Constraints n ≤ 100,000 where n is the length of counts k ≤ n Example 1 Input counts = [3, 3, 2, 5] k = 2 Output 6 Explanation Let's name the four item types [a, b, c, d] respectively. We can have the

View Solution →

K Stack Pops - Google Top Interview Questions

You are given two-dimensional list of integers stacks and an integer k. Assuming each list in stacks represents a stack, return the maximum possible sum that can be achieved from popping off exactly k elements from any combination of the stacks. Constraints n ≤ 500 where n is the number of rows in stacks. m ≤ 200 where m is the maximum number of elements in a stack. k ≤ 100 Example 1 Input stacks = [ [100, -3, -10], [1], [4, 5, 6] ] k = 4 Ou

View Solution →

Kth Last Node of a Linked List - Google Top Interview Questions

Given a singly linked list node, return the value of the kth last node (0-indexed). k is guaranteed not to be larger than the size of the linked list. This should be done in \mathcal{O}(1)O(1) space. Constraints n ≤ 100,000 where n is the length of node Example 1 Input node = [1, 2] k = 1 Output 1 Explanation The second last node has the val of 1 Example 2 Input node = [0, 1, 2, 3] k = 2 Output 1

View Solution →

Kth User to Visit Website- Google Top Interview Questions

You are given a two-dimensional list of integers requests and an integer k. Each element requests[i] contains [start, end] representing an inclusive interval for the possible times when user i visited the website. Each user visits the site exactly once. Return the users who may have been the kth (0-indexed) user to visit the site, sorted in ascending order. You can assume that the site can serve an unlimited number of users at any time. Constraints 1 ≤ n ≤ 100,000 where n is the

View Solution →

Largest One Submatrix with Column Swaps - Google Top Interview Questions

You are given a two-dimensional list of integers matrix containing 1s and 0s. Given that you can first rearrange the columns as many times as you want, return the area of the largest submatrix containing all 1s. Constraints 1 ≤ n * m ≤ 100,000 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [0, 0, 1], [1, 1, 1], [1, 0, 1] ] Output 4 Explanation We can rearrange the columns to: [[0, 1, 0], [1,

View Solution →