Longest Matrix Path Length - Google Top Interview Questions
You are given a two dimensional integer matrix where 0 is an empty cell and 1 is a wall. You can start at any empty cell on row 0 and want to end up on any empty cell on row n - 1. Given that you can move left, right, or down, return the longest such path where you visit each cell at most once. If there is no viable path, return 0. Constraints 1 ≤ n * m ≤ 200,000 where n and m are the number of rows and columns in matrix. Example 1 Input matrix = [ [0, 0, 0, 0],
View Solution →Longest Prefix Sequence - Google Top Interview Questions
You are given a list of lowercase alphabet strings words. Return the length of the longest sequence of words where each previous word is the prefix of the next word and the next word has just one new character appended. You can rearrange words in any order. Constraints 0 ≤ n ≤ 100,000 where n is the length of words 1 ≤ m ≤ 100,000 where m is the length of the longest string in words Example 1 Input words = ["abc", "ab", "x", "xy", "abcd"] Output 3 Explanation
View Solution →Longest Repeating Substring - Google Top Interview Questions
Given a lowercase alphabet string s, return the length of the longest substring that occurs at least two times in s. If there's no such string, return 0. Constraints 0 ≤ n ≤ 1,000 where n is the length of s Example 1 Input s = "abcdzabcd" Output 4 Explanation The longest substring that occurs more than once is "abcd". Example 2 Input s = "abcdefg" Output 0 Explanation There's no repeating substring.
View Solution →Look and Say - Google Top Interview Questions
The "look and say" sequence is defined as follows: beginning with the term 1, each subsequent term visually describes the digits appearing in the previous term. The first few terms are as follows: 1 11 <- 1 one 21 <- 2 ones 1211 <- 1 two, 1 one 111221 <- 1 one, 1 two, 2 ones 312211 <- 3 ones, 2 twos, 1 one Given an integer n, return the nth term of this sequence as a string. Constraints 1 ≤ n ≤ 40 Example
View Solution →Make a Palindrome by Inserting Characters - Google Top Interview Questions
Given a string s, return the minimum number of characters needed to be inserted so that the string becomes a palindrome. Constraints n ≤ 1,000 where n is the length of s Example 1 Input s = "radr" Output 1 Explanation We can insert "a" to get "radar"
View Solution →