## Largest Rectangle Submatrix - Amazon Top Interview Questions

Given a two-dimensional integer matrix consisting only of 1s and 0s, return the area of the largest rectangle containing only 1s. Constraints 0 ≤ n, m ≤ 250 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1, 0, 0, 0], [1, 0, 1, 1], [1, 0, 1, 1], [0, 1, 0, 0] ] Output 4 Explanation The biggest rectangle here is the 2 by 2 square of 1s on the right. Example 2 Input matrix = [ [1, 0, 0, 0, 0],

View Solution →## Least Frequently Used Cache - Amazon Top Interview Questions

Implement a least frequently used cache with the following methods: LFUCache(int capacity) constructs a new instance of a LFU cache with the given capacity. get(int key) retrieves the value associated with the key key. If it does not exist, return -1. As a side effect, this key's usage is incremented (used for eviction). set(int key, int val) updates the key key with value val. If updating this key-value pair exceeds capacity, then evicts the least frequently used key-value pair. If

View Solution →## Longest Arithmetic Subsequence - Amazon Top Interview Questions

Given a list of integers nums, return the length of the longest arithmetic subsequence. A sequence B[i] is defined as an arithmetic sequence if B[i+1] - B[i] have the same value for every 0 ≤ i < len(B) - 1. For example, [1, 5, 9, 13, 17] is the longest arithmetic subsequence of [-30, 1, 10, 5, 9, -20, 13, 17]. Constraints n ≤ 1,000 where n is the length of nums Example 1 Input nums = [1, 3, 5, 7, 9] Output 5 Explanation The whole array is arithmetic since the diff

View Solution →## Longest Increasing Path - Amazon Top Interview Questions

Given a two-dimensional integer matrix, find the length of the longest strictly increasing path. You can move up, down, left, or right. Constraints n, m ≤ 500 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1, 3, 5], [0, 4, 6], [2, 2, 9] ] Output 6 Explanation The longest path is [0, 1, 3, 5, 6, 9]

View Solution →## Longest Palindromic Subsequence - Amazon Top Interview Questions

Given a string s with all lower case characters, find the length of the longest palindromic subsequence in s. Constraints n ≤ 1,000 where n is the length of s Example 1 Input s = "rbaicneacrayr" Output 7 Explanation racecar is the longest palindromic subsequence of rbaicneacrayr Example 2 Input s = "binarysearch" Output 3 Explanation The longest palindromic subsequence here is aea. Example 3 Input s = "bbbbbbbbbb" Output 10 Explan

View Solution →