title-img


Shortest Bridge - Google Top Interview Questions

Given a two-dimensional list of integers matrix containing 0s and 1s, 0 represents water and 1 represents land. An island is a group of connecting 1s in 4 directions that are either surrounded by 0s or by the edges. Find the shortest bridge that connects two islands. It is guaranteed that there are two and only two islands. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [0, 1], [1, 0] ] Output

View Solution →

Shortest Common Supersequence - Google Top Interview Questions

Given strings a and b, return the length of the shortest string that has both a and b as subsequences. Example 1 Input a = "bell" b = "yellow" Output 7 Explanation One possible solution is "ybellow".

View Solution →

Shortest Window Substring in Order 🏂 - Google Top Interview Questions

Given a lowercase alphabet string s, return the length of the shortest substring containing all alphabet characters in order from "a" to "z". If there's no solution, return -1. Constraints 0 ≤ n ≤ 100,000 where n is the length of s Example 1 Input s = "aaaaabcbbdefghijklmnopqrstuvwxyzzz" Output 28 Explanation The shortest such substring is "abcbbdefghijklmnopqrstuvwxyz". The two additional "b"s contribute to the 2 extra characters. Example 2 Input s = "z

View Solution →

Split Digits to Sum Closest To Target - Google Top Interview Questions

You are given a string s and an integer target. s represents a decimal number containing digits from 0 to 9. You can partition s into as many parts as you want and take the sum of its parts. Afterwards, return the minimum possible absolute difference to target. Constraints 1 ≤ n, target ≤ 1,000 where n is the length of s Example 1 Input s = "112" target = 10 Output 3 Explanation We can partition s into "1" + "12" which sums to 13 and abs(13 - 10) = 3.

View Solution →

Sublists Containing Maximum and Minimum - Google Top Interview Questions

You are given a list of integers nums and you can remove at most one element in the list. Return the maximum number of sublists that contain both the maximum and minimum elements of the resulting list. The answer is guaranteed to fit in a 32-bit signed integer. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [2, 1, 5, 1, 3, 9] Output 8 Explanation If we remove 9 we'd get [2, 1, 5, 1, 3] and there's eight sublists where it contains b

View Solution →