Grid Coloring - Google Top Interview Questions
You are given a two-dimensional list of integers matrix. Each element matrix[r][c] represents a oolor 0 or 1. In one operation you can set the color of matrix[0][0] and all the connected (vertically and horizontally) cells that are of the same color as index (0, 0). Return the minimum number of operations required to change all cells in the matrix to the same color. Constraints 0 ≤ n, m ≤ 250 where n and m are the number of rows and columns in matrix matrix[r][c] = 0 or matrix[r][
View Solution →Half Monotonous String - Google Top Interview Questions
You are given a lowercase alphabet string s of even length consisting of lowercase alphabet letters. Return the minimum number of characters that need to be updated such that one of the following three conditions is true for all 0 ≤ i < n/2 and n/2 ≤ j < n: s[i] > s[j] or s[i] < s[j] or s[i] == s[j] Constraints 0 ≤ n ≤ 100,000 where n is the length of s Example 1 Input s = "aa" Output 0 Explanation This string already meets the s[i] == s[j] condition Exam
View Solution →Hill Maker - Google Top Interview Questions
You are given a two-dimensional list of integers matrix where matrix[r][c] represents the height of that cell. You are currently at top left corner and want to go to the bottom right. You can move to nearby cells (up, down, left, right) only if the neighboring cell's height is less than or equal to the current cell's height. Given that you can increase the height of any number of cells before you move, return the minimum total height that needs to be increased so that you can go to the bot
View Solution →H-Index - Google Top Interview Questions
In academia, the h-index is a metric used to calculate the impact of a researcher's papers. It is calculated as follows: A researcher has index h if at least h papers have at least h citations each. If there are multiple h satisfying this formula, the maximum is chosen. Given a list of paper citations of a researcher citations, calculate their h-index. Constraints n ≤ 100,000 where n is the length of citations Example 1 Input citations = [4, 3, 0, 1, 5] Output 3 Explanation At
View Solution →Hotel Room Assignments - Google Top Interview Questions
You are given a two-dimensional list of integers intervals where intervals[i] contains two numbers start and end representing a half-open interval [start, end). Each element represents requested times for a hotel room. Hotel rooms are assigned at the time that the booking starts. If requests intervals[i] and intervals[j] have the same starting time, then earlier index min(i, j) is assigned a room first. We assign rooms starting from 0 and in general use the smallest non-negative integ
View Solution →