title-img


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 →

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 →