title-img


String Isomorphism - Amazon Top Interview Questions

Given lowercase alphabet strings s, and t return whether you can create a 1-to-1 mapping for each letter in s to another letter (could be the same letter) such that s could be mapped to t, with the ordering of characters preserved. Constraints n ≤ 100,000 where n is the length of s m ≤ 100,000 where m is the length of t Example 1 Input s = "coco" t = "kaka" Output True Explanation We can create this mapping: "c" -> "k" "o" -> "a" Example 2 Input s = "cat

View Solution →

Minimum Distance of Two Words in a Sentence - Amazon Top Interview Questions

Given the strings text, word0, and word1, return the smallest distance between any two occurrences of word0 and word1 in text, measured in number of words in between. If either word0 or word1 doesn't appear in text, return -1. Constraints word0 and word1 are different. n ≤ 200,000 where n is the length of text. Example 1 Input text = "dog cat hello cat dog dog hello cat world" word0 = "hello" word1 = "world" Output 1 Explanation There's only one word "cat" in between th

View Solution →

Transpose of a Matrix - Amazon Top Interview Questions

Given an integer square (n by n) matrix, return its transpose. A transpose of a matrix switches the row and column indices. That is, for every r and c, matrix[r][c] = matrix[c][r]. Constraints n ≤ 100 Example 1 Input matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] Output [ [1, 4, 7], [2, 5, 8], [3, 6, 9] ]

View Solution →

ASCII String to Integer - Amazon Top Interview Questions

You are given a string s containing digits from "0" to "9" and lowercase alphabet characters. Return the sum of the numbers found in s. Constraints 1 ≤ n ≤ 100,000 where n is the length of s Example 1 Input s = "11aa32bbb5" Output 48 Explanation Since 11 + 32 + 5 = 48. Example 2 Input s = "abc" Output 0 Explanation There's no digits so it defaults to 0. Example 3 Input s = "1a2b30" Output 33 Explanation Since 1 + 2 + 30 = 33.

View Solution →

Arithmetic Sequence Permutation - Amazon Top Interview Questions

Given a list of integers nums, return whether you can rearrange the order of nums such that the difference between every consecutive two numbers is the same. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [7, 1, 5, 3] Output True Explanation If we rearrange nums to [1, 3, 5, 7], then the difference between every two consecutive numbers is 2. Example 2 Input nums = [1, 5, 1, 5, 1, 5] Output False Explanation The differenc

View Solution →