Delete From the Ends and Reinsert to Target - Google Top Interview Questions
You are given two strings s and t that are anagrams of each other. Consider an operation where we remove either the first or the last character in s and insert it back anywhere in the string. Return the minimum number of operations required to convert s into t. Constraints n ≤ 1,000 where n is the length of s Example 1 Input s = "edacb" t = "abcde" Output 3 Explanation The three operations are: We can remove "b" and insert it after "a" to get "edabc" W
View Solution →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 →