title-img


Smallest Number With No Adjacent Duplicates - Google Top Interview Questions

You are given a string s containing "1", "2", "3" and "?". Given that you can replace any “?” with "1", "2" or "3", return the smallest number you can make as a string such that no two adjacent digits are the same. Constraints n ≤ 100,000 where n is the length of s Example 1 Input s = "3?2??" Output "31212" Example 2 Input s = "???" Output "121"

View Solution →

Stuck Keyboard- Google Top Interview Questions

You are given two strings typed and target. You want to write target, but the keyboard is stuck so some characters may be written 1 or more times. Return whether it's possible that typed was meant to write target. Constraints n ≤ 100,000 where n is the length of typed m ≤ 100,000 where n is the length of s Example 1 Input typed = "aaabcccc" target = "abc" Output True Explanation Each of the "a", "b", and "c" were typed Example 2 Input typed = "abc"

View Solution →

Target Number with Operations - Google Top Interview Questions

Given positive integers start and end (start < end), return the minimum number of operations needed to convert start to end using these operations: Increment by 1 Multiply by 2 Constraints start < end < 2 ** 31 Example 1 Input start = 2 end = 9 Output 3 Explanation We can multiply 2 to get 4, and then again to get 8, then add 1 to get 9.

View Solution →

Toeplitz Matrix - Google Top Interview Questions

Given a two-dimensional matrix of integers matrix, determine whether it's a Toeplitz matrix. A Toeplitz is one where every diagonal descending from left to right has the same value. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [0, 1, 2], [3, 0, 1], [4, 3, 0], [5, 4, 3] ] Output True Example 2 Input matrix = [ [1, 0, 0], [0, 0, 0], [0, 0, 1] ]

View Solution →

Ambigram Detection- Google Top Interview Questions

You are given a lowercase alphabet string s and a two-dimensional list of strings pairs. Each element in pairs contains [a, b] meaning that character a and b are considered equivalent. We say that if a and b are equivalent and b and c are equivalent, then a and c are also equivalent. Also, any character a is equivalent to itself. Return whether s is a palindrome given the equivalence relations. Constraints 0 ≤ n ≤ 100,000 where n is the length of s 0 ≤ p ≤ 100,000 where p is th

View Solution →