Connected Road to Destination- Google Top Interview Questions
You are given integers sx, sy, ex, ey and two-dimensional list of integers roads. You are currently located at coordinate (sx, sy) and want to move to destination (ex, ey). Each element in roads contains (x, y) which is a road that will be added at that coordinate. Roads are added one by one in order. You can only move to adjacent (up, down, left, right) coordinates if there is a road in that coordinate or if it's the destination coordinate. For example, at (x, y) we can move to
View Solution →Count Rectangular Submatrices - Google Top Interview Questions
Given a two-dimensional list of integers matrix containing 1s and 0s, return the total number of submatrices with all 1 s. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix. Example 1 Input matrix = [ [1, 1, 0], [1, 1, 0], [0, 0, 0] ] Output 9 Explanation There's four 1 x 1 matrices. Theres two 2 x 1 matrices. There's two 1 x 2 matrices. And there's one 2 x 2 matrix.
View Solution →Count Submatrices That Sum Target - Google Top Interview Questions
You are given a two-dimensional integer matrix and an integer target. Return the number of submatrices in matrix whose sum equals target. Constraints 0 ≤ n, m ≤ 100 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [0, -1], [0, 0] ] target = 0 Output 5 Explanation We have three 1 x 1 submatrices, one 2 x 1 submatrix and one 1 x 2 submatrix.
View Solution →Decode Messages Sequel - Google Top Interview Questions
Given the mapping a = 1, b = 2, ... z = 26, as well as "*" which can be mapped anything from 1 to 9, and an encoded message message (as a string), count the number of ways it can be decoded. Mod the result by 10 ** 9 + 7. Constraints n ≤ 100,000 where n is the length of message Example 1 Input message = "1*" Output 18 Explanation The "*" can represent anything from 1 to 9, so this can be decoded as: ["aa", "ab", "ac", "ad", "ae", "af", "ag", "ah", "ai"] - (1,
View Solution →Delete Integers In Ascending Order - Google Top Interview Questions
You are given a list of unique integers nums and want to delete each number in ascending order. Return the indices of numbers in order of their deletion. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [3, 5, 1, 4, 2] Output [2, 3, 0, 1, 0] Explanation We delete the numbers in this order: Delete 1 at index 2 and now we have [3, 5, 4, 2] Delete 2 at index 3 and now we have [3, 5, 4] Delete 3 at index 0 and now we have [5, 4]
View Solution →