title-img


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 →

Rectangular Overlap - Amazon Top Interview Questions

You are given two lists of integers rect0 and rect1 representing coordinates (x0, y0, x1, y1) of two rectangles. (x0, y0) is the bottom left coordinate and (x1, y1) is the upper right coordinate. Return whether the two rectangles overlap. Note: if two rectangles touch only in their perimeters, they don't overlap. Example 1 Input rect0 = [0, 0, 10, 10] rect1 = [10, 10, 30, 30] Output False Example 2 Input rect0 = [0, 0, 10, 10] rect1 = [5, 5, 30, 30] Output T

View Solution →