title-img


Closest Distance to Character - Google Top Interview Questions

Given a string s and a character c, return a new list of integers of the same length as s where for each index i its value is set the closest distance of s[i] to c. You can assume c exists in s. Constraints n ≤ 100,000 where n is the length of s Example 1 Input s = "aabaab" c = "b" Output [2, 1, 0, 1, 1, 0]

View Solution →

Coincidence Search - Google Top Interview Questions

You are given a list of unique integers nums. Return the number of integers that could still be successfully found using a standard binary search. Binary search in pseudocode: lo = 0 hi = nums.size - 1 while lo <= hi mid = floor((lo + hi) / 2) if nums[mid] == target return mid elif nums[mid] < target lo = mid + 1 else hi = mid - 1 Constraints 0 ≤ n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [1, 5, 3, 2,

View Solution →

Inverted Subtree - Google Top Interview Questions

A tree is defined to be an inversion of another tree if either: Both trees are null Its left and right children are optionally swapped and its left and right subtrees are inversions. Given binary trees source and target, return whether there's some inversion T of source such that it's a subtree of target. That is, whether there's a node in target that is identically same in values and structure as T including all of its descendants. Constraints n ≤ 12 where n is the number of nodes in

View Solution →

K Numbers Greater Than or Equal to K - Google Top Interview Questions

You are given a list of non-negative integers nums. If there are exactly k numbers in nums that are greater than or equal to k, return k. Otherwise, return -1. Constraints 1 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [5, 3, 0, 9] Output 3 Explanation There are exactly 3 numbers that's greater than or equal to 3: [5, 3, 9].

View Solution →

Largest Elements in Their Row and Column - Google Top Interview Questions

You are given a two-dimensional list of integers matrix containing 1s and 0s. Return the number of elements in matrix such that: matrix[r][c] = 1 matrix[r][j] = 0 for every j ≠ c and matrix[i][c] = 0 for every i ≠ r Constraints 0 ≤ n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [0, 0, 1], [1, 0, 0], [0, 1, 0] ] Output 3 Explanation We have matrix[0][2], matrix[1][0] and matrix[2][1] meet the criteria.

View Solution →