title-img


Swap Characters Once to Minimize Differences - Google Top Interview Questions

You are given two lowercase alphabet strings s and t of the same length. Given that you can make at most one swap between two characters in s, return the minimum number of indices where s[i] ≠ t[i]. Constraints 1 ≤ n ≤ 100,000 where n is the length of s and t Example 1 Input s = "abbz" t = "zcca" Output 2 Explanation We can swap "a" and "z" to turn s into "zbba". Then there's 2 characters that differ between t. Example 2 Input s = "zfba" t = "zbca"

View Solution →

The Accountant - Google Top Interview Questions

Spreadsheets often use this alphabetical encoding for its columns: "A", "B", "C", ..., "AA", "AB", "AC", ..., "ZZ", "AAA", "AAB", "AAC", .... Given a column number n, return its alphabetical column id. For example, given 1, return "A". Given 27, return "AA". Constraints 1 ≤ n < 2 ** 31 Example 1 Input n = 1 Output "A" Example 2 Input n = 2 Output "B" Example 3 Input n = 26 Output "Z" Example 4 Input n = 27 Output "AA"

View Solution →

Three Doubled Numbers - Google Top Interview Questions

Given a list of integers nums, return the number of triples i < j < k such that nums[i] * 2 = nums[j] and nums[j] * 2 = nums[k]. Constraints 0 ≤ n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 0, 2, 4, 4] Output 2 Explanation There's [1, 2, 4] (with indices 0,2, and 3) and [1, 2, 4] (with indices 0, 2, 4) Example 2 Input nums = [4, 2, 1] Output 0

View Solution →

Trail to Minimize Effort - Google Top Interview Questions

You are given a two-dimensional list of integers matrix where element represents the height of a hill. You are currently on the top left cell and want to go to the bottom right cell. In each move, you can go up, down, left, or right. A path's cost is defined to the largest absolute difference of heights between any two consecutive cells in the path. Return the minimum cost of any path. Constraints 1 ≤ n, m ≤ 250 where n and m are the number of rows and columns in matrix

View Solution →

Valid State of List - Google Top Interview Questions

Given a list of integers nums, return whether every number can be grouped using one of the following rules: You can form contiguous pairs (a, a) You can form contiguous triplets (a, a, a) You can form contiguous triplets (a, a + 1, a + 2) Constraints n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [7, 7, 3, 4, 5] Output True Explanation We can group [7, 7] together and [3, 4, 5] together. Example 2 Input nums = [1, 3, 2] Out

View Solution →