title-img


Matrix Search Sequel - Amazon Top Interview Questions

Given a two-dimensional integer matrix, where every row and column is sorted in ascending order, return whether an integer target exists in the matrix. This should be done in \mathcal{O}(n + m)O(n+m) time. Constraints n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1, 3, 9], [2, 5, 10], [5, 7, 13] ] target = 7 Output True

View Solution →

Number of Hops - Amazon Top Interview Questions

Given an integer list nums where each number represents the maximum number of hops you can make, return the minimum number of hops it would take to reach the last index starting at index 0. You can assume that you can always reach the last index. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [3, 3, 2, 0, 1] Output 2 Explanation We can jump from index 0 to 1 and then jump straight to the last index by jumping 3 steps.

View Solution →

Number of K-Divisible Pairs - Amazon Top Interview Questions

You are given a list of integers nums and an integer k. Return the number of pairs i < j such that (nums[i] + nums[j]) % k = 0 Constraints n ≤ 100,000 where n is the length of nums 1 ≤ k ≤ 100 Example 1 Input nums = [2, 4, 5, 1, 2] k = 6 Output 3 Explanation We have the following pairs [2, 4] [4, 2] [5, 1] Example 2 Input nums = [3, 7, 2] k = 7 Output 0

View Solution →

Number of Palindromic Substrings - Amazon Top Interview Questions

Given a lowercase alphabet string s, return the number of palindromic substrings in s. Constraints 1 ≤ n ≤ 1,000 where n is the length of s Example 1 Input s = "tacocat" Output 10 Explanation The palindromic substrings are: "t" "a" "c" "o" "c" "a" "t" "coc" "acoca" "tacocat"

View Solution →

One Edit Distance - Amazon Top Interview Questions

Given two strings s0 and s1 determine whether they are one or zero edit distance away. An edit can be described as deleting a character, adding a character, or replacing a character with another character. Constraints n ≤ 100,000 where n is the length of s0. m ≤ 100,000 where m is the length of s1. Example 1 Input s0 = "quicksort" s1 = "quicksort" Output True Explanation This has the edit distance of 0, since they are the same string. Example 2 Input s0 =

View Solution →