title-img


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 →

Phone Number Combinations - Amazon Top Interview Questions

Given a string digits containing 2 to 9 inclusive, return in sorted lexicographic order all possible strings it could represent when mapping to letters on a phone dialpad. These are the mappings on a phone dialpad: | 2 | abc | | 3 | def | | 4 | ghi | | 5 | jkl | | 6 | mno | | 7 | pqrs | | 8 | tuv | | 9 | wxyz | Example 1 Input digits = "23" Output ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]

View Solution →

Removing Parentheses - Amazon Top Interview Questions

Given a string of parentheses s, return the minimum number of parentheses to be removed to make the string balanced. Constraints n ≤ 100,000 where n is the length of s Example 1 Input s = "()())()" Output 1 Explanation We can remove the ")" at index 4 to make it balanced. Example 2 Input s = ")(" Output 2 Explanation We must remove all the parentheses.

View Solution →