Cut Palindrome - Amazon Top Interview Questions
Given two strings a and b of equal length, return whether it is possible to cut both strings at a common point such that the first part of a and the second part of b form a palindrome. Constraints n ≤ 100,000 where n is the length of a and b Example 1 Input a = "cat" b = "pac" Output True Explanation If we cut the strings into "c" + "at" and "p" + "ac", then "c" + "ac" is a palindrome. Example 2 Input a = "iceboat" b = "racecar" Output True Explanat
View Solution →Binary Tree Nodes Around Radius - Amazon Top Interview Questions
You are given a binary tree root containing unique integers and integers target and radius. Return a sorted list of values of all nodes that are distance radius away from the node with value target. Constraints 1 ≤ n ≤ 100,000 where n is number of nodes in root 0 ≤ distance ≤ 100,000 Example 1 Input root = [3, [5, null, null], [2, [1, [6, null, null], [9, null, null]], [4, null, null]]] target = 4 radius = 2 Output [1, 3] Example 2 Input root = [0, null, null] t
View Solution →Add Linked Lists - Amazon Top Interview Questions
Given a singly linked list l0 and another linked list l1, each representing a number with least significant digits first, return the summed linked list. Note: Each value in the linked list is guaranteed to be between 0 and 9. Constraints n ≤ 100,000 where n is the number of nodes in l0 m ≤ 100,000 where m is the number of nodes in l1 Example 1 Input l0 = [6, 4] l1 = [4, 7] Output [0, 2, 1] Explanation This is 46 + 74 = 120
View Solution →Making Change Sequel - Amazon Top Interview Questions
Given a list of integers denominations and an integer amount, find the minimum number of coins needed to make amount. Return -1 if there's no way to make amount. Constraints n ≤ 10 where n is the length of denominations. amount ≤ 500,000. Example 1 Input denominations = [1, 5, 10, 25] amount = 60 Output 3 Explanation We can make 60 with 2 quarters and 1 dime. Example 2 Input denominations = [3, 7, 10] amount = 8 Output -1 Explanation We can't
View Solution →Submajority Vote - Amazon Top Interview Questions
You are given a list of integers nums where each number represents a vote to a candidate. Return the ids of the candidates that have greater than \lfloor \frac{n}{3}\rfloor⌊ 3 n ⌋ votes, in ascending order. Bonus: solve in \mathcal{O}(1)O(1) space. Constraints n ≤ 100,000 where n is the length of nums. Example 1 Input nums = [2, 1, 5, 5, 5, 5, 6, 6, 6, 6, 6] Output [5, 6] Explanation Both 5 and 6 have 40% of the votes. Example 2 Input nums = [1,
View Solution →