title-img


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 →

Sublist with Largest Min-Length Product - Google Top Interview Questions

You are given a list of integers nums and an integer pos. Find a sublist A of nums that includes the index (0-indexed) pos such that min(A) * A.length is maximized and return the value. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [-1, 1, 4, 3] pos = 3 Output 6 Explanation The best sublist is [4, 3]. Since min(4, 3) = 3 and its length is 2 we have 3 * 2 = 6.

View Solution →