title-img


Every Sublist Containing Unique Element - Google Top Interview Questions

Given a list of integers nums, return whether every sublist has at least 1 element in it which occurs exactly once in the sublist. Note: the intended solution should run \mathcal {O}(n)O(n) for random inputs on average. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [0, 2, 4, 2, 0] Output True Explanation Every sublist in nums has at least one element whose frequency is one. For example, the sublist [2, 4, 2] has 4. [0, 2, 4, 2] has 0 and 4. Exa

View Solution →

Every Sublist Min Sum- Google Top Interview Questions

You are given a list of integers nums. Return the sum of min(x) for every sublist x in nums. Mod the result by 10 ** 9 + 7. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 2, 4, 3] Output 20 Explanation We have the following sublists and their mins: min([1]) = 1 min([1, 2]) = 1 min([1, 2, 4]) = 1 min([1, 2, 4, 3]) = 1 min([2]) = 2 min([2, 4]) = 2 min([2, 4, 3]) = 2 min([4]) = 4 min([4, 3]) = 3 min([3]

View Solution →

Fruit Basket Packing - Google Top Interview Questions

You are given a two-dimensional list of integers fruits. Each fruits[i] contains [cost, size, total], meaning that fruit i costs cost each, each one has size of size, and there are total of total of them. You're also given k number of fruit baskets of capacity capacity. You want to fill the fruit baskets with the following constraints in this order: Each basket can only contain fruits of the same kind Each basket should be as full as possible Each basket should be as cheap as pos

View Solution →

First to Count to Target- Google Top Interview Questions

You are playing a game against a friend where in each round you pick a number from 1 to k to add to a shared running total that initially starts from 0. The first person to reach or exceed the running total to target wins. Given that you go first, return whether you can force a win if everyone plays optimally. Constraints k ≤ 30 target ≤ 1,000 Example 1 Input k = 5 target = 9 Output True Explanation If we pick 3 first, then whether your friend picks 1, 2, ..

View Solution →

Gene Mutation Groups - Google Top Interview Questions

You are given a list of unique strings genes where each element has the same length and contains characters "A", "C", "G" and/or "T". If strings a and b are the same string except for one character, then a and b are in the same mutation group. If strings a and b are in a group and b and c are in a group, then a and c are in the same group. Return the total number of mutation groups. Constraints n ≤ 10,000 k ≤ 20 where k is the length of a string in genes Example 1 Input

View Solution →