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 →Next Integer Permutation - Amazon Top Interview Questions
Given an integer n, return the next bigger permutation of its digits. If n is already in its biggest permutation, rotate to the smallest permutation. Constraints n < 2 ** 31 Example 1 Input n = 527 Output 572 Example 2 Input n = 321 Output 123 Explanation 321 is already the biggest permutation so it rotates to the smallest. Example 3 Input n = 20 Output 2
View Solution →N Queens Puzzle - Amazon Top Interview Questions
The n queens puzzle asks to place n queens on an n×n chessboard so that no two queens are attacking each other. Given a partially filled two-dimensional integer matrix where 1 represents a queen and 0 represents an empty cell, return whether this configuration of the board can solve the puzzle. Constraints 1 ≤ n ≤ 15 Example 1 Input matrix = [ [1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 1, 0] ] Output True Exp
View Solution →Number Stream to Intervals - Amazon Top Interview Questions
Implement a data structure with the following methods: StreamSummary() constructs a new instance. add(int val) adds the number val to the instance. int[][] get() returns a sorted list of disjoint intervals summarizing the numbers we've seen so far. Constraints n ≤ 10,000 where n is the number of calls to add m ≤ 10,000 where n is the number of calls to get Example 1 Input methods = ["constructor", "add", "add", "add", "add", "get"] arguments = [[], [1], [3], [2], [9
View Solution →