Minimum Number of Flips to Have Alternating Values - Google Top Interview Questions
You are given a string s containing "1"s and "0"s. You can take some prefix of s and move it to the back. Afterwards, return the minimum number of characters that need to be flipped such that the string never has any two consecutive characters of the same value. Constraints n ≤ 100,000 where n is the length of s Example 1 Input s = "001010111" Output 1 Explanation After we move the first character "0" to the back we get "010101110". Then we can flip the 3rd las
View Solution →Minimum Number of Transfers to Settle Debts - Google Top Interview Questions
You are given a two-dimensional list of integers transfers containing [source, dest, amount], which means that person source lent person dest a dollar amount equal to amount. Return the minimum number of person-to-person transfers that are required so that all debts are paid. Constraints n ≤ 13 where n is the number of participants Example 1 Input transfers = [ [0, 1, 50], [1, 2, 50] ] Output 1 Explanation Person 0 gave person 1 $50 and person 1 gave p
View Solution →Moo - Google Top Interview Questions
You are given a string cows representing the initial conditions of some cows. Each cow can take one of three values: "L", meaning the cow is charging to the left. "R", meaning the cow is charging to the right. "@", meaning the cow is standing still. Cows charging on a direction will pick up other cows unless the cow receives a force from the opposite direction. Then, it will stand still. Return the orientation of each cow when the cow stop charging. Constraints
View Solution →Minimum Light Radius - Google Top Interview Questions
You are given a list of integers nums representing coordinates of houses on a 1-dimensional line. You have 3 street lights that you can put anywhere on the coordinate line and a light at coordinate x lights up houses in [x - r, x + r], inclusive. Return the smallest r required such that we can place the 3 lights and all the houses are lit up. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [3, 4, 5, 6] Output 0.5 Explanation If we p
View Solution →Number of Decrements to Reach Zero - Google Top Interview Questions
You are given an integer n. In one operation you can either Decrement n by one If n is even, decrement by n / 2 If n is divisible by 3, decrement by 2 * (n / 3) Return the minimum number of operations required to decrement n to zero. Constraints n ≤ 10 ** 9 Example 1 Input n = 15 Output 5 Explanation Since n = 15 is divisible by 3 we decrement by 10 = 2 * (15 / 3) to get 5. Then we decrement by one to get 4. Then we decrement by 2 since n is even.
View Solution →