Drop a Ball Down the Stairs - Google Top Interview Questions
You are given an integer height and a list of integers blacklist. You are currently standing at height height and you are playing a game to move a small ball down to height 0. In even rounds (0, 2, 4, 6 etc.) you can move the ball down 1, 2, or 4 stairs down. In odd rounds, you can move the ball down 1, 3, or 4 stairs. There are some levels of the stairs where if the ball lands there, it will die as labelled in blacklist. Return number of ways you can move the ball down to height 0. Mo
View Solution →Embolden - Google Top Interview Questions
Given a string text and a list of strings patterns, implement an embolden function where all substrings in text that match any string in patterns are wrapped in <b> and </b> tags. If two patterns are adjacent or overlap, they should be merged into one tag. Constraints n < 5000 where n is the length of text m < 100 where m is the length of patterns Example 1 Input text = "abcdefg" patterns = ["bc", "ef"] Output "a<b>bc</b>d<b>ef</b>g" Explanation bc and ef match
View Solution →Enclosed Islands - Google Top Interview Questions
You are given a two-dimensional integer matrix of 1s and 0s. A 1 represents land and 0 represents water. From any land cell you can move up, down, left or right to another land cell or go off the matrix. Return the number of land cells from which we cannot go off the matrix. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [0, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0] ] Output 4
View Solution →Equivalent Product Pairs - Google Top Interview Questions
You are given a list of unique positive integers nums. Return the number of quadruples (a, b, c, d) in nums such that a * b = c * d and a, b, c, and d are all pairwise distinct. Constraints 0 ≤ n ≤ 1,000 where n is the length of nums Example 1 Input nums = [2, 3, 4, 6] Output 8 Explanation We have the following (a, b, c, d) [3,4,2,6] [4,3,2,6] [3,4,6,2] [4,3,6,2] [2,6,3,4] [2,6,4,3] [6,2,3,4] [6,2,4,3]
View Solution →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 →