title-img


Run-Length Encoding - Amazon Top Interview Questions

Given a string s, return its run-length encoding. You can assume the string to be encoded have no digits and consists solely of alphabetic characters. Constraints n ≤ 100,000 where n is the length of s Example 1 Input s = "aaaabbbccdaa" Output "4a3b2c1d2a" Example 2 Input s = "abcde" Output "1a1b1c1d1e" Example 3 Input s = "aabba" Output "2a2b1a" Example 4 Input s = "aaaaaaaaaa" Output "10a"

View Solution →

Sum of Two Numbers - Amazon Top Interview Questions

Given a list of numbers nums and a number k, return whether any two elements from the list add up to k. You may not use the same element twice. Note: Numbers can be negative or 0. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [35, 8, 18, 3, 22] k = 11 Output True Explanation 8 + 3 = 11 Example 2 Input nums = [10, 36, 22, 14] k = 4 Output False Explanation No two numbers in this list add up to 4. Example 3

View Solution →

Vertical Lines in Binary Tree - Amazon Top Interview Questions

Given a binary tree root, return the number of unique vertical lines that can be drawn such that every node has a line intersecting it. Each left child is angled at 45 degrees to its left, while the right child is angled at 45 degrees to the right. For example, root and root.left.right are on the same vertical line. Constraints 1 ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [1, [2, [3, null, null], null], [4, null, [5, null, null]]] Output 5

View Solution →

24 - Amazon Top Interview Questions

You are given a list of four integers nums, each between 0 and 9, in a fixed order. By placing the operators +, -, *, and / (where / is integer division) between the numbers, and grouping them with parentheses, determine whether it is possible to get the value 24. Constraints n = 4 where n is the length of nums 0 ≤ nums[i] ≤ 9 Example 1 Input nums = [5, 2, 7, 8] Output True Explanation We can do (5 * 2 - 7) * 8 = 24 Example 2 Input nums = [7, 9, 7, 4] Ou

View Solution →

8-Puzzle - Amazon Top Interview Questions

You are given a 3x3 board of unique integers from 0 to 8, representing the state of a puzzle. In this puzzle, you can swap the 0 with one of its 4 neighbours (if it exists), and you are trying to solve it by obtaining the following configuration: [[0, 1, 2], [3, 4, 5], [6, 7, 8]] Return the minimum number of swaps required to solve the puzzle, or return -1 if it's not possible. Constraints n = 3 where n is the number of rows and columns in board 0 ≤ board[r][c] ≤ 8 Example 1

View Solution →