Largest One Submatrix with Column Swaps - Google Top Interview Questions
You are given a two-dimensional list of integers matrix containing 1s and 0s. Given that you can first rearrange the columns as many times as you want, return the area of the largest submatrix containing all 1s. Constraints 1 ≤ n * m ≤ 100,000 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [0, 0, 1], [1, 1, 1], [1, 0, 1] ] Output 4 Explanation We can rearrange the columns to: [[0, 1, 0], [1,
View Solution →Largest Tree Sum Path - Google Top Interview Questions
Given a binary tree root, return the largest sum of any path between any two nodes. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [-6, [5, null, null], [4, [7, [4, [2, null, null], null], [8, null, null]], [12, null, null]]] Output 31 Explanation The largest sum path is: [8, 7, 4, 12]
View Solution →Lazy Run-Length Decoding - Google Top Interview Questions
Implement a data structure RunLengthDecoder which implements the following methods: RunLengthDecoder(string s) which takes a string s that is run-length encoded. string value(int i) which returns the character at index i of the run-length decoded version of s. string valueInRange(string c, int i, int j) which returns the first lowercase alphabet character that is greater than or equal to c from the range [i, j) of the decoded string. You can assume that the range contains characters
View Solution →Leaf Pairs Less Than Target Distance Away - Google Top Interview Questions
You are given a binary tree root and an integer target. Return the number of pairs of leaves such that the shortest distance between them is less than or equal to target. Constraints 0 ≤ n, target ≤ 1,000 where n is the number of nodes in root Example 1 Input root = [1, [2, [4, null, null], [5, null, null]], [3, null, null]] target = 2 Output 1 Explanation The pair (4, 5) meet the distance criteria since the distance between them is 2. Example 2 Input root
View Solution →Lexicographically Smallest Leaf to Root Path- Google Top Interview Questions
Given a binary tree root containing digits from 0 to 9, return the lexicographically smallest leaf to root path. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, [8, null, null], [7, [4, [6, null, null], [3, null, null]], [5, null, null]]] Output [3, 4, 7, 1]
View Solution →