Count Substrings With All 1s - Google Top Interview Questions
You are given a string s containing "1"s and "0"s. Return the number of substrings that contain only "1"s. Mod the result by 10 ** 9 + 7. Constraints 0 ≤ n ≤ 100,000 where n is the length of s Example 1 Input s = "111001" Output 7 Explanation Here are all the substrings containing only "1"s: "1" "1" "1" "1" "11" "11" "111"
View Solution →CPU Scheduling - Google Top Interview Questions
You are given a two-dimensional list of integers tasks. Each element contains [id, queue_time, duration] which represents a CPU task with id id, queued at time queue_time, that will run for duration amount of time. All tasks have unique ids. Given that the CPU scheduler will run a job that is currently in the queue with the lowest duration first, return the order of job ids that will be processed. If there's more than one job with the lowest duration, then it will run the job with lowest
View Solution →Cut Ribbons of Same Length - Google Top Interview Questions
You are given a list of positive integers ribbons and an integer k. Given that you can cut the ribbons as many times as you want, return the largest r such that you can have k ribbons of length r. If there is no solution, return -1. Constraints 1 ≤ n ≤ 100,000 where n is the length of ribbons 1 ≤ k Example 1 Input ribbons = [1, 2, 3, 4, 9] k = 5 Output 3 Explanation We can cut the ribbon of size 9 into 3 pieces of size 3 each. Then cut the ribbon of size 4 in
View Solution →Delete Characters to Equalize Strings - Google Top Interview Questions
Given two lowercase alphabet strings a and b, consider an operation where we delete any character in either string. Return the minimum number of operations required such that both strings are equal. Constraints 0 ≤ n ≤ 1,000 where n is the length of a 0 ≤ m ≤ 1,000 where m is the length of b Example 1 Input a = "zyyx" b = "yfyx" Output 2 Explanation We delete the "z" in a and delete "f" in b
View Solution →Delete From the Ends and Reinsert to Target - Google Top Interview Questions
You are given two strings s and t that are anagrams of each other. Consider an operation where we remove either the first or the last character in s and insert it back anywhere in the string. Return the minimum number of operations required to convert s into t. Constraints n ≤ 1,000 where n is the length of s Example 1 Input s = "edacb" t = "abcde" Output 3 Explanation The three operations are: We can remove "b" and insert it after "a" to get "edabc" W
View Solution →