title-img


Number of Moves to Capture the King - Google Top Interview Questions

You are given a two-dimensional integer matrix board containing 0s, 1s and 2s representing some n x n chessboard. Each 0 represents an empty cell, 1 represents the knight and 2 represents the king. There is at least one knight but exactly one king. Given that the king stays still, return the minimum number of moves it would take for some knight to land on the king. If there's no solution, return -1. A knight can't land on another knight. Constraints 2 ≤ n ≤ 500 where n is th

View Solution →

Number of Non-Overlapping Sublists With Sum of Target - Google Top Interview Questions

You are given a list of integers nums and an integer target. Return the maximum number of non-overlapping, non-empty sublists that exist such that each sublist's sum is target. Constraints 0 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [4, 3, 7, 5, -3, 10] target = 7 Output 3 Explanation We can have [4, 3], [7] and [-3, 10]

View Solution →

Number of Operations to Decrement Target to Zero - Google Top Interview Questions

You are given a list of positive integers nums and an integer target. Consider an operation where we remove a number v from either the front or the back of nums and decrement target by v. Return the minimum number of operations required to decrement target to zero. If it's not possible, return -1. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [3, 1, 1, 2, 5, 1, 1] target = 7 Output 3 Explanation We can remove 1, 1 and 5 from the

View Solution →

Path to Maximize Probability to Destination - Google Top Interview Questions

You are given a two-dimensional list of integers edges, a list of floats success, and integers start and end. edges represents an undirected, weighted graph. Each edges[i] contains [u, v] meaning u and v is connected, and the chance of successfully traversing the edge is success[i] chance. Given that you start at node start and you want to arrive at node end, return the highest overall chance you can get by taking any path. If there's no path to end, return 0. Constraints 1 ≤ n ≤ 10

View Solution →

Peak Heights 🦖 - Google Top Interview Questions

You are given a two-dimensional integer matrix containing 0s and 1s where 0 represents water and 1 represents land. Return a new matrix of the same dimensions where we increase the height of every land cell as much as possible given that: The height of any water cell stays 0 Any cell can differ by at most 1 unit of height between neighboring cells (up, down, left, right) You can assume there is at least one water cell. Constraints n, m ≤ 250 where n and m are the number of rows

View Solution →