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 →Longest Sublist with K Distinct Numbers - Amazon Top Interview Questions
Given an integer k and a list of integers nums, return the length of the longest sublist that contains at most k distinct integers. Constraints 0 ≤ k ≤ n ≤ 100,000 where n is the length of nums Example 1 Input k = 2 nums = [0, 1, 2, 1, 0] Output 3 Explanation The longest substring with 2 distinct integers is [1,2,1], which has length of 3. Example 2 Input k = 1 nums = [0, 0, 0, 0, 0] Output 5 Example 3 Input k = 1 nums = [0, 1, 2, 3, 4]
View Solution →Merge New Interval - Amazon Top Interview Questions
Given a list of intervals that are: Non-overlapping Sorted in increasing order by end times Merge a new interval target into the list so that the above two properties are met. Constraints n ≤ 100,000 where n is the length of intervals Example 1 Input intervals = [ [1, 10], [20, 30], [70, 100] ] target = [5, 25] Output [ [1, 30], [70, 100] ] Explanation [5, 25] is merged with the first two intervals [1, 10], [20, 30]. Example 2 I
View Solution →