title-img


Partition String - Amazon Top Interview Questions

Given a lowercase alphabet string s, partition s into as many pieces as possible such that each letter appears in at most one piece and return the sizes of the partitions as a list. Constraints 0 ≤ n ≤ 100,000 where n is the length of s Example 1 Input s = "cocoplaydae" Output [4, 1, 1, 4, 1] Explanation The string is split to["coco", "p", "l", "ayda", "e"].

View Solution →

Pick Up Gold in Two Locations - Amazon Top Interview Questions

You are given a two-dimensional list of integers matrix and integers row, col, erow0, ecol0, erow1, and ecol1. You are currently at matrix[row][col] and want to pick up gold that is at matrix[erow0][ecol0] and matrix[erow1][ecol1]. You can move up, down, left, and right but when you are at a cell (r, c), you incur cost matrix[r][c], although if you land at a cell more than once, you don't incur that cost again. Return the minimum cost to pick up gold at both locations. Constraints n, m

View Solution →

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 →