## 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

## 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.

## Cutting Binary Search Tree - Amazon Top Interview Questions

Given a binary search tree root, an integer lo, and another an integer hi, remove all nodes that are not between [lo, hi] inclusive. Constraints n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [2, [1, [0, null, null], null], [4, [3, null, null], null]] lo = 3 hi = 4 Output [4, [3, null, null], null] Example 2 Input root = [5, [1, null, null], [9, [7, [6, null, null], [8, null, null]], [10, null, null]]] lo = 7 hi = 10 Output [9, [

## Swap Kth Node Values - Amazon Top Interview Questions

You are given a singly linked list node and an integer k. Swap the value of the k-th (0-indexed) node from the end with the k-th node from the beginning. Constraints 1 ≤ n ≤ 100,000 where n is the number of nodes in node 0 ≤ k < n Example 1 Input node = [1, 2, 3, 4, 5, 6] k = 1 Output [1, 5, 3, 4, 2, 6] Explanation We swap 2 and 5. Example 2 Input node = [0, 6, 8, 2, 9] k = 2 Output [0, 6, 8, 2, 9] Explanation We swap 8 with 8.

## Sum of Nodes with Even Grandparent Values - Amazon Top Interview Questions

Given a binary tree root, return the sum of all node values whose grandparents have an even value. Constraints 0 ≤ n ≤ 100,000 where n is the number of nodes in root Example 1 Input root = [8, [4, [6, null, null], [7, null, [2, null, null]]], [3, null, null]] Output 15 Explanation Nodes 6, 7, and 2 have an even value grandparent.