Knight Remains - Amazon Top Interview Questions
You are given four integers n, x, y, and k. n represents an n by n chessboard and x, y represents a knight positioned at (x, y). The knight has to take exactly k steps, where at each step it chooses any of the 8 directions uniformly at random. Return the percentage chance rounded down to the nearest integer that the knight remains in the chessboard after taking k steps, with the condition that it can’t enter the board again once it leaves it. Constraints 1 ≤ n ≤ 25 0 ≤ k ≤ 100 Examp
View Solution →Count Contained Intervals - Amazon Top Interview Questions
You are given a two-dimensional list of integers intervals. Each value is unique and contains an inclusive interval [start, end]. Return the number of intervals are contained by another interval. An interval that's contained by multiple other intervals should only be counted once. An interval [s0, e0] contains another interval [s1, e1] if s0 ≤ s1 and e0 ≥ e1. Constraints 0 ≤ n ≤ 100,000 where n is the length of intervals Example 1 Input intervals = [ [1, 5], [2, 3],
View Solution →Reflected Binary Code - Amazon Top Interview Questions
Given an integer n, return the nth (0-indexed) gray code number. Gray code is a way of ordering binary numbers such that each consecutive number's values differ by exactly one bit. The first few gray codes are: [0, 1, 11, 10, 110, 111, ...] Constraints 0 ≤ n ≤ 1,000,000 Example 1 Input n = 3 Output 2
View Solution →Longest Common Subsequence - Amazon Top Interview Questions
Given two strings a and b, return the length of their longest common subsequence. Constraints n ≤ 1,000 where n is the length of a m ≤ 1,000 where m is the length of b Example 1 Input a = "abcvc" b = "bv" Output 2 Explanation bv is the longest common subsequence. Example 2 Input a = "abc" b = "abc" Output 3 Example 3 Input a = "abc" b = "def" Output 0 Example 4 Input a = "binarysearch" b = "searchbinary" Output 6
View Solution →Palindrome Linked List - Amazon Top Interview Questions
Given a singly linked list node whose values are integers, determine whether the linked list forms a palindrome. Constraints n ≤ 100,000 where n is the length of node Example 1 Input node = [5, 3, 5] Output True Explanation 5 -> 3 -> 5 is a palindrome. Example 2 Input node = [12, 8, 12] Output True Explanation The values of the linked list are the same forwards and backwards.
View Solution →