Amazon
2000+ Interview Questions and Answers
Given an array of numbers, find the maximum sum of any contiguous subarray of the array.
For example, given the array [34, -50, 42, 14, -5, 86], the maximum sum would be 137, since we would ...read more
You are given the arrival and departure times of N trains at a railway station in a day. You need to find the minimum of platforms required for the railway station such that no ...read more
Q3. Every time I enter a temple my money gets doubled and while leaving u have to donate 100 like this I go to 4 temple and when I leave the 4th temple I will have no money left so what was the money I had when I e...
read moreThe person had no money when they entered the first temple.
The person's money gets doubled every time they enter a temple.
They have to donate 100 when leaving each temple.
After visiting 4 temples, they have no money left.
Therefore, they must have had no money when they entered the first temple.
Q4. If a seller wants to sell a phone worth 60k at 7k on amazon then would you allow him? If not then why? And what are the things you wanna confirm before allowing him to sell his product in your website?
No, I would not allow the seller to sell the phone at such a low price. I would confirm the authenticity of the product and the seller's credentials.
Confirm authenticity of the product
Verify seller's credentials
Check for any suspicious activity or fraud
Ensure compliance with Amazon's policies and guidelines
Q5. What is the difference between a good customer service and bad customer service?
Good customer service is helpful, efficient, and personalized, while bad customer service is unresponsive, rude, and impersonal.
Good customer service is helpful and goes above and beyond to assist customers.
Good customer service is efficient and resolves issues promptly.
Good customer service is personalized and treats each customer as an individual.
Bad customer service is unresponsive and fails to address customer concerns.
Bad customer service is rude and lacks empathy toward...read more
You have been given two strings ‘str1’ and ‘str2’ of length N and M respectively. Your task is to check whether string ‘str2’ contains one of the permutations of string ‘str1’ as its substr...read more
You are given an array/list 'ARR' of ‘N’ integers, and ‘Q’ queries. Each query can be of two types:
Given 2 integers ‘L’,’R’ ( L>=0 and R Given an index ‘i’ update the value of ARR[i] to a given int...read more
Given an index ‘i’ update the value of ARR[i] to a given int...read more
There is a river which flows in one direction. One day, the river has 'N' number of fishes. You are given an array 'FISHES' of integers representing the size of 'N' fishes. The fishes are present in t...read more
Given a generic tree, find the count of all special nodes. A node is a special node if there is a path from root to that node with all distinct elements. The input was not a p...read more
Given a Singly Linked List of integers, delete all the alternate nodes in the list.
Example:
List: 10 -> 20 -> 30 -> 40 -> 50 -> 60 -> null Alternate nodes will be: 20, 40, and 60. Hence a...read more
You have been given two Strings “STR1” and “STR2” of characters. Your task is to find the length of the longest common subsequence.
A String ‘a’ is a subsequence of a String ‘b’ if ‘a’...read more
Given two unsorted arrays of non-negative integers, 'arr1' and 'arr2' of size 'N' and 'M', respectively. Your task is to find the pair of elements (one from each array), such t...read more
Q13. A man walks into his office and every time if there are people in the lift he takes it till 10th floor till his cabin if he is alone he only takes it till 7 and returning back he takes the lift till ground floo...
read moreThe man takes the lift till 7th floor when alone because he is too short to reach the button for the 10th floor.
The man takes the lift till 10th floor when there are people because they can press the button for him.
He takes the lift till ground floor when returning because he doesn't need to go to his cabin anymore.
This is a riddle question.
You are given a matrix 'MAT' of size ‘N’ * ‘M’, where ‘N’ is the number of rows and ‘M’ is the number of columns. Value ‘0’ in a cell represents that the cell is set on fire initially, (at tim...read more
You are given an array/list of ‘N’ integers. You are supposed to return the maximum sum of the subsequence with the constraint that no two elements are adjacent in the given...read more
You are given an array of integers 'ARR' of length 'N' and an integer Target. Your task is to return all pairs of elements such that they add up to Target.
Note:
We cannot use the element at a given inde...read more
Q17. There is a 12 km road and a contractor who is in-charge of repairing it. Contractor updates you about the work which is done in patches. Like “Road between 3.2 km to 7.9 km repaired ”, “Road between 1.21 km to ...
read moreThe longest continuous patch of a road repaired by a contractor is determined.
Iterate through the updates and keep track of the start and end points of each patch
Calculate the length of each patch and update the longest patch if necessary
Return the start and end points of the longest patch
You are given a non-empty binary tree where each node has a non-negative integer value. Return the maximum possible sum of path between any two leaves of the given tree.
The p...read more
You are working as a cab driver. Your car moves in a straight line and moves toward the forward direction only. Initially, you have ‘C’ empty seats for the passengers.
Now, you are given ‘N’ number ...read more
You have been given an array 'PRICES' consisting of 'N' integers where PRICES[i] denotes the price of a given stock on the i-th day. You are also given an integer 'K' denoting the...read more
You are given an array consisting of 'N' non-negative integers, and two non-negative integers 'K' and 'M', your task is to find a pair of indices(s...read more
You are given an array consisting of N integers, and an integer, K. Your task is to determine the total sum of the minimum element and the maximum...read more
For a given array with N elements, you need to find the length of the longest subsequence from the array such that all the elements of the subsequence are sorted in strictly increa...read more
The task is to find the length of the longest increasing subsequence in a given array.
Iterate through the array and keep track of the length of the longest increasing subsequence seen so far.
Use dynamic programming to solve the problem efficiently.
The time complexity of the solution should be O(N^2) or better.
Consider edge cases such as an empty array or an array with only one element.
For a given integer array/list 'ARR' of size 'N' containing all distinct values, find the total number of 'Inversions' that may exist.
An inversion is defined for a pair of integers in the array...read more
You have been given a binary matrix of size 'N' * 'M' where each element is either 0 or 1. You are also given a source and a destination cell, both of them lie within the matrix....read more
Given a string (STR) of length N, you have to create a new string by performing the following operation:
Take the smallest character from the first 'K' characters of STR, remove it from ST...read more
A Derangement is a permutation of ‘N’ elements, such that no element appears in its original position. For example, an instance of derangement of {0, 1, 2, 3} is {2, 3, 1, 0}, because 2 prese...read more
Mike is a little boy who loves solving math problems. One day he was playing with his mom’s mobile. The mobile keypad contains 12 buttons { 10 digits(0-9) and 2 characters(‘*’ and ‘#’) }. Mike w...read more
You have been given stock values/prices for N number of days. Every i-th day signifies the price of a stock on that day. Your task is to find the maximum profit which you can make by buying and sel...read more
You have been given an integer array/list(ARR) of size 'N'. It only contains 0s, 1s and 2s. Write a solution to sort this array/list.
Note :
Try to solve the problem in 'Single Scan'. ' Single Scan' ...read more
Q31. If a customer placed an order for DSLR camera worth 50k and chose COD as payment option, how will you investigate this situation?
I would verify the authenticity of the order and the customer before proceeding with the delivery.
Check the customer's order history and account details
Verify the customer's contact information
Confirm the delivery address
Check for any suspicious activity or signs of fraud
Contact the customer to confirm the order and payment method
If necessary, involve law enforcement or security personnel
You have been given a grid containing some oranges. Each cell of this grid has one of the three integers values:
You are given a 2-D array 'MATRIX' of dimensions N x M, of integers. You need to return the spiral path of the matrix.
Example Of Spiral Path:
Input Format:
The first line contains an integer 'T' ...read more
You are given a directed graph having ‘N’ nodes. A matrix ‘EDGES’ of size M x 2 is given which represents the ‘M’ edges such that there is an edge directed from node EDGES[i][0] ...read more
You are given an array ‘Arr’ consisting of ‘N’ distinct integers and a positive integer ‘K’. Find out Kth smallest and Kth largest element of the array. It is guaranteed...read more
You are present at point ‘A’ which is the top-left cell of an M X N matrix, your destination is point ‘B’, which is the bottom-right cell of the same matrix. Your task is to find the total number of...read more
We are suffering from the Second wave of Covid-19. The Government is trying to increase its vaccination drives. Ninja wants to help the Government to plan an effective method to help increase v...read more
You have been given an integer array/list(arr) and a number 'Sum'. Find and return the total number of pairs in the array/list which when added, results equal to the 'Sum'.
Note:
Given ...read more
Given an array/list of integers of length ‘N’, there is a sliding window of size ‘K’ which moves from the beginning of the array, to the very end. You can only see the ‘K’ nu...read more
You have been given a grid containing some oranges. Each cell of this grid has one of the three integers values:
Given a maze in the form of a binary rectangular matrix of size M*N, where each element can either be 0 or 1, the task is to find the length of the shortest path in a maze from a g...read more
You are given an N*M binary matrix, considering for every 0-cell(cell with value = 0) the distance from this cell to its nearest 1-cell(cell with value = 1) is 'di', you need to find the max...read more
You are given an arbitrary binary tree. A binary tree is called special if every node of this tree has either zero or two children. You have to determine if the given binary tree is special ...read more
You are given an array 'ARR' of integers of length N. Your task is to find the first missing positive integer in linear time and constant space. In other words, find the lowest positive in...read more
The task is to find the lowest positive integer that does not exist in the given array of integers.
Iterate through the array and mark the positive integers as visited using the array indices.
Iterate through the marked array and return the index of the first unmarked element.
If all positive integers are marked, return the length of the array + 1 as the missing positive integer.
You are given an array/list ARR consisting of N integers. Your task is to find the length of the longest decreasing subsequence.
A subsequence is a sequence of numbers obtained by ...read more
Given a binary array 'ARR' of size 'N', your task is to find the longest sequence of continuous 1’s that can be formed by replacing at-most 'K' zeroes by ones. Return the length of this ...read more
You have been given 'N' ropes of different lengths, we need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. We need to conn...read more
Given a string, determine if it is a palindrome, considering only alphanumeric characters.
Palindrome
A palindrome is a word, number, phrase, or other sequences of characters which read the sam...read more
Given a string 'S' of length 'L', return the length of the longest substring without repeating characters.
Example:
Suppose given input is "abacb", then the length ...read more
You are given a string (STR) of length N.
Your task is to find the longest palindromic substring. If there is more than one palindromic substring with the maximum length, return the...read more
You have been given a long type array/list 'ARR' of size 'N'. It represents an elevation map wherein 'ARR[i]' denotes the elevation of the 'ith' bar. Print the total amount of rainwater that c...read more
You have been given a sorted array/list ARR consisting of ‘N’ elements. You are also given an integer ‘K’.
Now, your task is to find the first and last occur...read more
You have been given two integers ‘NUM1’ and ‘NUM2’ as a string. Your task is to print the sum of both the numbers.
Input Format:
The first line contains a single integer ‘T’ representing the ...read more
You are given an array ‘ARR’ consisting of ‘N’ strings. Your task is to find the longest common prefix among all these strings. If there is no common prefix, you have to return an empty str...read more
Given a singly linked list of integers. Your task is to return the head of the reversed linked list.
For example:
The given linked list is 1 -> 2 -> 3 -> 4-> NULL. Then the reverse...read more
You are given an unweighted directed graph of 'V' vertices and 'E' edges. Your task is to print all the strongly connected components (SCCs) present in the grap...read more
Implement a SpecialStack Data Structure that supports getMin() in O(1) time and O(1) extra space along with push(), pop(), top(), isEmpty()...read more
You have been given a sentence ‘S’ in the form of a string and a word ‘W’, you need to find whether the word is present in the given sentence or not. The word must...read more
Design and implement a data structure for Least Recently Used (LRU) cache to support the following operations:
1. get(key) - Return the value of the key if the key exists in the cache, o...read more
Given a sequence of ‘N’ space-separated non-negative integers A[1],A[2],A[3],......A[i]…...A[n]. Where each number of the sequence represents the height of the line drawn at point 'i'. ...read more
Given a sequence of non-negative integers representing the height of lines on a cartesian plane, find two lines that form a container with the maximum area of water.
Use two pointers approach to find the maximum area
Start with the widest container and gradually move the pointers towards each other
Calculate the area at each step and update the maximum area
The area is calculated as the minimum height of the two lines multiplied by the distance between them
Pre-requisites: Anagrams are defined as words or names that can be formed by rearranging letters of another word. Such as "spar" can be formed by rearranging letters of "rasp". Hence, "spar" and "...read more
You are given two strings ‘S’ and ‘T’. Your task is to find the minimum (Contiguous) substring ‘W’ of ‘S’, such that ‘T’ is a subsequence of ‘W’
A subsequence is a sequence that can be...read more
An expression is called the postfix expression if the operator appears in the expression after the operands.
Example :
Infix expression: A + B * C - D Postfix expression: A B + C...read more
You have been given an undirected graph of ‘V’ vertices (labeled 0,1,..., V-1) and ‘E’ edges. Each edge connecting two nodes (‘X’,’Y’) will have a weight denoting the distance between no...read more
Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5 islands
Example:
Input : mat[][] = {{1, 1, 0, 0, 0},
{0,...read more
Q66. What happens if a seller is adamant on not understanding a policy and you can't do anything plus you cannot say No to the seller too?
If a seller is adamant on not understanding a policy, try to explain it in a different way and provide examples. If they still refuse, escalate to a higher authority.
Try to understand the seller's perspective and address their concerns
Provide clear and concise explanations of the policy
Use examples to illustrate the policy
If the seller still refuses to comply, escalate the issue to a higher authority
Ninjaland is a country in the shape of a 2-Dimensional grid 'GRID', with 'N' rows and 'M' columns. Each point in the grid has some cost associated with it.
Find a path from top left i.e. (0, 0) ...read more
You are given an infinite supply of coins of each of denominations D = {D0, D1, D2, D3, ...... Dn-1}. You need to figure out the total number of ways W, in which you can make a change fo...read more
Bob lives with his wife in a city named Berland. Bob is a good husband, so he goes out with his wife every Friday to ‘Arcade’ mall.
‘Arcade’ is a very famous mall in Berland. It has a very unique t...read more
You are given a string 'S' of length 'N', you need to find the frequency of each of the characters from ‘a’ to ‘z’ in the given string.
Example :
Given 'S' : abcdg Then output will be : 1 1 1 1 0...read more
You are given 'N' jobs with their start time 'Start', end time 'End' and profit 'Profit'. You need to tell the maximum profit you can obtain by performing these jobs such that no two jobs...read more
One day Ninja Misha and Ninja Andrew (students of the Ultimate Ninja Ankush) were playing a very simple game. First, each player chooses an integer in the range from 1 to ‘N’. Let...read more
Given an array ARR of N integers and an integer S. The task is to find whether there exists a subarray(positive length) of the given array such that the sum of elements of the subarray eq...read more
You are given an integer array 'ARR' of size 'N' and an integer 'S'. Your task is to return the list of all pairs of elements such that each sum of elements of each pair equals 'S'.
Note:
Each pair shou...read more
Given an array and a target sum, find all pairs of elements in the array that add up to the target sum.
Create an empty list to store the pairs
Iterate through the array and for each element, check if there is a complement (target sum minus the current element) in the array
If a complement is found, add the pair (current element, complement) to the list
Sort the list of pairs in non-decreasing order of their first value
If two pairs have the same first value, sort them based on th...read more
You are given a sorted array 'ARR' and a number 'X'. Your task is to count the number of occurrences of 'X' in 'ARR'.
Note :
1. If 'X' is not found in the array, return 0. 2. The give...read more
The task is to count the number of occurrences of a given number in a sorted array.
Use binary search to find the first and last occurrence of the given number in the array.
Subtract the indices of the first and last occurrence to get the count.
Handle the case when the number is not found in the array.
You have been given a binary tree of integers. Your task is to print the boundary nodes of this binary tree in Anti-Clockwise direction starting from the root node.
NOTE:
The boundary nodes of...read more
You have been given an integer K.
Your task is to generate all binary strings of length K such that there are no consecutive 1s in the string. This means that the binary str...read more
Given a linked list having two pointers in each node. The first one points to the next node of the list, however, the other pointer is random and can point to any node ...read more
You are given an arbitrary array ‘arr’ consisting of N non-negative integers, where every element appears thrice except one. You need to find the element that appears only once.
Input F...read more
You are given an array “A” of N integers. Your task is to find the maximum element in all K sized contiguous subarrays from left to right.
For Example:
If A = [3, 2, 3], and K ...read more
Q81. Difference between online and offline shopping.
Online shopping allows for convenience and a wider selection, while offline shopping offers a more tactile and personal experience.
Online shopping can be done from anywhere with an internet connection
Offline shopping allows customers to physically see and touch products before purchasing
Online shopping often offers a wider selection of products and better prices
Offline shopping can provide a more personalized experience with knowledgeable staff and in-store events
Examples of ...read more
You have been given a Binary Tree of integers.
Your task is to print the Right view of it.
The right view of a Binary Tree is a set of nodes visible when the tree is viewed from the Right side and the...read more
You are given two strings S and X containing random characters. Your task is to find the smallest substring in S which contains all the characters present in X.
Example:
Let S = “abdd” and X = “b...read more
You are given an array (ARR) of length N, consisting of integers. You have to find the sum of the subarray (including empty subarray) having maximum sum among all subarrays.
A subarray is a ...read more
Q85. What is the good quality of a sales man?
A good quality of a salesperson is their ability to listen and understand the customer's needs.
Active listening skills
Empathy towards customers
Ability to understand customer's pain points
Effective communication skills
Ability to build rapport with customers
Persistence and resilience
Product knowledge
Ability to close deals
You have been given a matrix of ‘N’ rows and ‘M’ columns filled up with integers where every row is sorted in non-decreasing order. Your task is to find the overall median of the matrix i.e if all ...read more
You have been given an integer ‘X’ and a non-decreasing sorted doubly linked list with distinct nodes.
Your task is to return t...read more
There are ‘N’ people at a party. Each person has been assigned a unique id between 0 to 'N' - 1(both inclusive). A celebrity is a person who is known to everyone but does not know anyone at...read more
You are given an array of integers ARR[] of size N consisting of zeros and ones. You have to select a subset and flip bits of that subset. You have to return the count of maximum one’s that you can obt...read more
You have been given an array/list ‘ARR’ consisting of ‘N’ positive integers. Your task is to return the Next Greater Element(NGE) for every element.
The Next Greater Element for an element ‘...read more
Given an encoded string where repetitions of substrings are represented as substring followed by count of substrings. For example, if encrypted string is “ab2cd2” and k=4...read more
Given a square binary matrix ‘mat[n][n]’, find ‘K’ such that all elements in the Kth row are ‘0’ and all elements in the Kth column are ‘1’. The value of mat[k][k] can be anything (either ‘0’ or ‘1’)....read more
Given an array 'ARR'' of 'N' integers and an integer 'target', your task is to find three integers in 'ARR' such that the sum is closest to the target.
Note
In the case of two closest sums, print the...read more
You are given a string of lowercase characters. Your task is to rearrange (reorder) the string in such a way that no two adjacent characters are the same.
You have to return the rearranged strin...read more
You are given two strings 'A' and 'B' of words. Your task is to find out the most frequent and lexicographically smallest word in string 'A', which is not present in string 'B'. If no such wor...read more
Ninjaland is a country having 'N' states numbered from 1 to 'N'. These 'N' states are connected by 'M' bidirectional roads. Each road connects to different states and has some cost to travel ...read more
The task is to select 'N' - 1 roads in a country with 'N' states, such that the tourist bus can travel to every state at least once at minimum cost.
The problem can be solved using a minimum spanning tree algorithm, such as Kruskal's algorithm or Prim's algorithm.
Create a graph representation of the country using the given roads and their costs.
Apply the minimum spanning tree algorithm to find the minimum cost roads that connect all the states.
Print the selected roads and thei...read more
You have been given an array/list 'WORDS' of 'N' non-empty words, and an integer 'K'. Your task is to return the 'K' most frequent words sorted by their frequency from highest to lowest.
N...read more
You are given a binary tree with ‘N’ number of nodes and a node ‘X’. Your task is to print the path from the root node to the given node ‘X’.
A binary tree is a hierarchical data structure in whic...read more
You have been given two integers 'N' and 'D', Your task is to find the square root of the number 'N' with precision up to 'D' decimal places i.e. the difference between your answer and the...read more
You have been given two arrays, 'AT' and 'DT', representing the arrival and departure times of all trains that reach a railway station.
Your task is to find the minimum number of plat...read more
More about working at Amazon
Top HR Questions asked in null
Interview Process at null
Top Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month