Stack Sequence - Google Top Interview Questions
Given a list of distinct integers pushes, and another list of integers pops, return whether this is a valid sequence of stack push and pop actions. Constraints n ≤ 100,000 where n is the length of pushes m ≤ 100,000 where m is the length of pops Example 1 Input pushes = [0, 1, 4, 6, 8] pops = [1, 0, 8, 6, 4] Output True Explanation We can first push [0, 1], then pop both off. Then push [4, 6, 8] and then pop them all off. Example 2 Input pushes = [1,
View Solution →String Construction - Google Top Interview Questions
You are given a list of strings strings where each string contains "A"s and "B"s. You are also given integers a and b. Return the maximum number of strings that can be constructed given that you can use at most a "A"s and at most b "B"s, without reuse. Constraints n ≤ 50 where n is the length of strings a, b ≤ 50 Example 1 Input strings = ["AABB", "AAAB", "A", "B"] a = 4 b = 2 Output 3 Explanation We can take these strings using 4 "A"s and 2 "B"s ["AAAB
View Solution →Sum of Three Numbers Less than Target - Google Top Interview Questions
Given a list of integers nums and an integer target, return the number of triples i < j < k that exist such that nums[i] + nums[j] + nums[k] < target. Constraints n ≤ 1,000 where n is the length of nums Example 1 Input nums = [-3, 5, 3, 2, 7] target = 9 Output 5 Explanation Here are the different triples' values: -3 + 5 + 3 = 5 -3 + 5 + 2 = 4 -3 + 3 + 2 = 2 -3 + 3 + 7 = 7 -3 + 2 + 7 = 6
View Solution →Sum of Three Numbers Sequel - Google Top Interview Questions
Given a list of integers nums and an integer k, find three distinct elements in nums, a, b, c, such that abs(a + b + c - k) is minimized and return the absolute difference. Constraints n ≤ 1,000 where n is length of nums. Example 1 Input nums = [2, 4, 25, 7] k = 15 Output 2 Explanation Taking [2, 4, 7] will get us closest to 15 and the absolute difference is abs(13 - 15) = 2.
View Solution →Sum of Three Numbers Trequel - Google Top Interview Questions
Given a list of positive integers nums, consider three indices i < j < k such that nums[i] ≤ nums[j] ≤ nums[k]. Return the maximum possible nums[i] + nums[j] + nums[k]. You can assume that a solution exists. Constraints 3 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [9, 1, 5, 3, 4] Output 8 Explanation We pick [1, 3, 4] for a total sum of 8
View Solution →