title-img


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 →

Nearest Bus Stop From a House - Google Top Interview Questions

You are given a two-dimensional integer matrix containing 0s, 1s, 2s, and 3s where 0 represents an empty cell 1 represents a wall 2 represents a house 3 represents a bus stop Return the shortest distance from any house to any bus stop. You can move up, down, left, and right but you can't move through a house or a wall cell. If there's no solution, return -1. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [

View Solution →

Next Node on Its Right - Google Top Interview Questions

You are given a binary tree root containing unique values, and an integer target. Find the node with value target and return the node that's directly right of it on its level. If the target node doesn't exist or if it's already in the rightmost position, return null. Constraints 0 ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input Visualize tree = [1, [2, [4, null, null], [5, null, null]], [3, null, [6, [7, null, null], null]]] target = 5 Output

View Solution →

Non-Overlapping Pairs of Sublists - Google Top Interview Questions

Given a list of integers nums and a positive integer k, return the number of pairs of non-overlapping sublists such that all the elements in each sublist have value greater than or equal to k. Mod the result by 10 ** 9 + 7. Constraints n ≤ 100,000 where n is the length of nums 1 ≤ k Example 1 Input nums = [3, 4, 4, 9] k = 4 Output 5 Explanation These are the pairs of sublists: [4], [9] [4], [9] (using other 4) [4], [4] [4, 4], [9] [4], [4,

View Solution →

Number of Concatenations to Create Subsequence- Google Top Interview Questions

You are given two lowercase alphabet strings s and t. Return the minimum number of times we must concatenate s such that t is a subsequence of s. For example, if we concatenate "abc" three times, we'd get "abcabcabc". If it's not possible, return -1. Constraints 1 ≤ n ≤ 100,000 where n is the length of s 1 ≤ m ≤ 100,000 where m is the length of t Example 1 Input s = "dab" t = "abbd" Output 3 Explanation If we concatenate a = "dab" three times, we can get

View Solution →