title-img


Look and Say - Amazon Top Interview Questions

The "look and say" sequence is defined as follows: beginning with the term 1, each subsequent term visually describes the digits appearing in the previous term. The first few terms are as follows: 1 11 <- 1 one 21 <- 2 ones 1211 <- 1 two, 1 one 111221 <- 1 one, 1 two, 2 ones 312211 <- 3 ones, 2 twos, 1 one Given an integer n, return the nth term of this sequence as a string. Constraints 1 ≤ n ≤ 40 Example 1 Input n = 3

View Solution →

File System - Amazon Top Interview Questions

Implement a data structure with the following methods: bool create(String path, int content) which creates a path at path if there's a parent directory and path doesn't exist yet, and sets its value as content. Returns whether it was newly created. Initially only the root directory at "/" exists. int get(String path) which returns the value associated with path. If there's no path, return -1. Constraints 0 ≤ n ≤ 100,000 where n is the number of calls to create and get Example 1 Inp

View Solution →

Wildfire - Amazon Top Interview Questions

You are given a two-dimensional integer matrix representing a forest where a cell is: 0 if it's empty 1 if it's a tree 2 if it's a tree on fire Every day, a tree catches fire if there is an adjacent (top, down, left, right) tree that's also on fire. Return the number of days it would take for every tree to be on fire. If it's not possible, return -1. Constraints 0 ≤ n * m ≤ 200,000 where n and m are the number of rows and columns in matrix Example 1 Input matrix = [ [1,

View Solution →

Anagram Substrings - Amazon Top Interview Questions

Given two strings s0 and s1, return the number of substrings where s1 contains any anagram of s0. Constraints n ≤ 100,000 where n is the length of s0 m ≤ 100,000 where m is the length of s1 Example 1 Input s0 = "abc" s1 = "bcabxabc" Output 3 Explanation The substrings "bca", "cab" and "abc" of s0 are permutations of "abc".

View Solution →

Shortest Sublist to Remove to Make Sorted List - Amazon Top Interview Questions

Given a list of integers nums, return the length of the shortest sublist that you can remove such that the resulting list is in ascending order. Constraints n ≤ 100,000 where n is the length of nums Example 1 Input nums = [1, 1, 3, 5, 4, 2, 1, 9] Output 3 Explanation If we remove [4, 2, 1], then the list would be sorted in ascending order: [1, 1, 3, 5, 9].

View Solution →