title-img


Points on a Line- Amazon Top Interview Questions

You are given a two-dimensional list of integers coordinates. Each list contains two integers [x, y] representing a point on the Cartesian plane. Return the maximum number of points that lie on some line. Constraints n ≤ 1,000 where n is the length of coordinates Example 1 Input coordinates = [ [5, 1], [7, 2], [9, 3], [0, 0], [1, 1], [5, 5], [6, 6] ] Output 4 Explanation The points [[0, 0], [1, 1], [5, 5], [6, 6]] all fall in a li

View Solution →

Prefix with Equivalent Frequencies - Amazon Top Interview Questions

You are given a list of integers nums. Return the length of the longest prefix of nums such that after we remove one element in the prefix, each number occurs the same number of times. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [5, 5, 3, 7, 3, 9] Output 5 Explanation If we pick the prefix [5, 5, 3, 7, 3] and remove 7 then every number would occur twice.

View Solution →

Regular Expression Matching - Amazon Top Interview Questions

Implement regular expression matching with the following special characters: . (period) which matches any single character * (asterisk) which matches zero or more of the preceding element That is, implement a function that takes in a valid regular expression pattern and a string s and returns whether or not the string matches the regular expression. Note: The input pattern is guaranteed not to have consecutive asterisks. Constraints n ≤ 100 where n is the length of pattern m ≤ 1

View Solution →

Rolling Median - Amazon Top Interview Questions

Implement a RollingMedian class with the following methods: add(int val) which adds val to the data structure median() which retrieves the current median of all numbers added Median of [1, 2, 3] is 2 whereas median of [1, 2, 3, 4] is 2.5. Constraints n ≤ 100,000 where n is the number of calls to add and median Example 1 Input methods = ["constructor", "add", "add", "add", "median", "add", "median"] arguments = [[], [1], [2], [3], [], [4], []]` Output [None, None, Non

View Solution →

Sliding Window Max - Amazon Top Interview Questions

Given a list of integers nums and an integer k, return the maximum values of each sublist of length k. Constraints 1 ≤ n ≤ 100,000 where n is the length of nums. 1 ≤ k ≤ 100,000. Example 1 Input nums = [10, 5, 2, 7, 8, 7] k = 3 Output [10, 7, 8, 8] Explanation 10 = max(10, 5, 2) 7 = max(5, 2, 7) 8 = max(2, 7, 8) 8 = max(7, 8, 7) Example 2 Input nums = [1, 2, 3, 4, 5, 4, 3, 2, 1] k = 3 Output [3, 4, 5, 5, 5, 4, 3] Example 3 Input

View Solution →