title-img


Count Nodes in Complete Binary Tree - Google Top Interview Questions

Given a complete binary tree root, return the number of nodes in the tree. This should be done in \mathcal{O}((\log n)^2)O((logn) 2 ). Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, [2, [4, null, null], [5, null, null]], [3, null, null]] Output 5 Example 2 Input root = [1, [2, [4, null, null], [5, null, null]], [3, [6, null, null], [7, null, null]]] Output 7

View Solution →

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 →