Add office photos
Amazon logo
Engaged Employer

Amazon

Verified
4.1
based on 25.2k Reviews
Video summary
Proud winner of ABECA 2024 - AmbitionBox Employee Choice Awards
Filter interviews by
SDE
Fresher
Skills
Clear (1)

40+ Amazon SDE Interview Questions and Answers

Updated 24 Aug 2024
Asked in
SDE Interview

Q1. 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 more
Ans.

The longest continuous patch of a road being 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

View 1 answer
right arrow
Asked in
SDE Interview

Q2. There are n nuts and n bolts represented in two different arrays and a function is_fit(nut_i, bolt_j) which returns 0 if its perfectly fit, 1 if it’s a tight fit and -1 if its loose fit. I was asked to arrange...

read more
Ans.

Arrange nuts and bolts so that every nut fits perfectly with the bolt in the same position.

  • Sort both arrays in the same order using a comparison function

  • Use a binary search to find the matching bolt for each nut

  • Repeat until all nuts are matched with bolts

Add your answer
right arrow
Amazon SDE Interview Questions and Answers for Freshers
illustration image
Asked in
SDE Interview

Q3. A stream of data is coming. Maintain records in a page and mechanism to see previous and next page. (Concept of Doubly Linked List) (It is always advisable to ask questions in design questions. The interviewers...

read more
Ans.

A thread is a unit of execution within a process that can run independently and concurrently with other threads.

  • Threads allow for concurrent execution of tasks within a program.

  • Threads share the same memory space and resources of the process they belong to.

  • Threads can communicate and synchronize with each other through shared data structures like locks and semaphores.

  • Threads can improve performance by utilizing multiple CPU cores or by handling I/O operations asynchronously.

  • E...read more

Add your answer
right arrow
Asked in
SDE Interview

Q4. Write an efficient program to count number tree structures that can be made using n number of nodes. Basically T(n)=summation (T(i) * T(n-i-1)). I used DP as there are a lot of sub-problems used again and again...

read more
Ans.

The program counts the number of tree structures that can be made using n nodes.

  • Use dynamic programming to solve the problem efficiently

  • Break down the problem into subproblems and store their solutions in an array

  • Iterate through the array to calculate the number of tree structures

  • The time complexity of the program is O(n^2)

Add your answer
right arrow
Discover Amazon interview dos and don'ts from real experiences
Asked in
SDE Interview

Q5. Design a system for finding the costliest element always whenever we pick up an element from a box.(concept of Max Heap)

Ans.

Design a system using Max Heap to find the costliest element from a box when an element is picked.

  • Implement a Max Heap data structure to store the elements in the box.

  • Whenever an element is picked, the costliest element can be found at the root of the Max Heap.

  • After picking an element, update the Max Heap by removing the root and reorganizing the heap.

  • Ensure the Max Heap property is maintained during insertion and deletion operations.

  • Example: If the box contains elements [5, ...read more

Add your answer
right arrow
Asked in
SDE Interview

Q6. What happens on server side on receiving HTTP requests and how operating system interacts and then discussion related with threading, thread pool ,synchronization, hashing etc

Ans.

When a server receives an HTTP request, it interacts with the operating system, handles threading, thread pooling, synchronization, and hashing.

  • Upon receiving an HTTP request, the server creates a new thread to handle the request.

  • The operating system manages the allocation of system resources to the server process.

  • Thread pooling is used to efficiently manage and reuse threads for handling multiple requests.

  • Synchronization mechanisms like locks or semaphores are used to ensure...read more

Add your answer
right arrow
Are these interview questions helpful?
Asked in
SDE Interview

Q7. Make a data structure and implement an algorithm to print all the files in a directory. (the root directory can have sub-directories too.) I used an n-ary tree and BFS to print files. It can also be done using...

read more
Ans.

Implement a data structure and algorithm to print all files in a directory, including sub-directories.

  • Use an n-ary tree or stack to represent the directory structure

  • Implement a BFS or DFS algorithm to traverse the directory and print files

  • Handle sub-directories recursively

  • Consider using a queue or stack to keep track of directories to visit

Add your answer
right arrow
Asked in
SDE Interview

Q8. Write a program to show whether a graph is a tree or not using adjacency matrix

Ans.

Program to determine if a graph is a tree using adjacency matrix

  • A graph is a tree if it is connected and has no cycles

  • Check if the graph is connected by performing a depth-first search or breadth-first search

  • Check if the graph has cycles by performing a depth-first search and tracking visited nodes

Add your answer
right arrow
Share interview questions and help millions of jobseekers 🌟
man with laptop
Asked in
SDE Interview

Q9. Given a sorted array which can have repeated elements, find the occurrence of an element. (Most optimal solution is O(logn) – Using binary search to find start and end occurrence)

Ans.

Given a sorted array with repeated elements, find the occurrence of a given element using binary search.

  • Use binary search to find the first occurrence of the element

  • Use binary search to find the last occurrence of the element

  • Calculate the occurrence by subtracting the indices of the last and first occurrences and adding 1

Add your answer
right arrow
Asked in
SDE Interview

Q10. Describe transaction process in detail if we want to transfer from one account to other. Also design scheme for it

Ans.

The transaction process involves transferring funds from one account to another. A scheme is designed to ensure secure and accurate transfers.

  • Verify the availability of sufficient funds in the sender's account

  • Authenticate the sender's identity and authorization for the transaction

  • Deduct the transfer amount from the sender's account balance

  • Initiate a request to transfer the funds to the recipient's account

  • Validate the recipient's account details

  • Add the transferred amount to th...read more

Add your answer
right arrow
Asked in
SDE Interview

Q11. What are the differences between graph and tree?

Ans.

Graphs are non-linear data structures with cycles while trees are hierarchical data structures without cycles.

  • Graphs can have cycles while trees cannot

  • Graphs can have multiple root nodes while trees have only one

  • Graphs can have disconnected components while trees are always connected

  • Graphs can have directed or undirected edges while trees have only directed edges

  • Examples of graphs include social networks, road networks, and computer networks while examples of trees include fi...read more

Add your answer
right arrow
Asked in
SDE Interview

Q12. Explain the approach of LRU cache and implement using object oriented language

Ans.

LRU cache is a data structure that stores most recently used items and discards least recently used items.

  • LRU stands for Least Recently Used

  • It is implemented using a doubly linked list and a hash map

  • When an item is accessed, it is moved to the front of the list

  • When the cache is full, the least recently used item is removed from the end of the list

  • Example: A web browser cache that stores recently visited web pages

Add your answer
right arrow
Asked in
SDE Interview

Q13. You will be given the number of pairs of parenthesis. Find out the total possible valid unique combinations and there should not be any duplicity. Write code

Ans.

Find total possible valid unique combinations of given number of pairs of parenthesis without duplicity.

  • Use recursion to generate all possible combinations

  • Check for validity of each combination using a stack

  • Use a set to avoid duplicity

Add your answer
right arrow
Asked in
SDE Interview

Q14. Given an in-order traversal of a special binary tree having property that the node is always greater than its left and right child. Construct the tree and write code

Ans.

Construct a binary tree from in-order traversal with nodes greater than left and right child.

  • The root node will be the maximum value in the in-order traversal

  • Recursively construct the left and right subtrees using the left and right portions of the in-order traversal

  • Repeat until all nodes are added to the tree

Add your answer
right arrow
Asked in
SDE Interview

Q15. What is the definition of tree ?

Ans.

A tree is a data structure consisting of nodes connected by edges, with a single root node and no cycles.

  • Nodes represent elements of the tree, and edges represent the relationships between them.

  • Each node can have zero or more child nodes, and each child node can have its own children.

  • Trees are commonly used in computer science for organizing and searching data, such as in binary search trees.

  • Examples of trees include file systems, family trees, and HTML document object models...read more

Add your answer
right arrow
Asked in
SDE Interview

Q16. When can you say a graph to be a tree?

Ans.

A graph can be called a tree if it is connected and has no cycles.

  • A tree is a type of graph with no cycles.

  • It must be connected, meaning there is a path between any two vertices.

  • It has n-1 edges, where n is the number of vertices.

  • Examples include family trees, file directory structures, and decision trees.

Add your answer
right arrow
Asked in
SDE Interview

Q17. Given two linked lists, one i/p and one o/p, identify the pattern in them and code the logic. It was a reversal of the two halves of a linked list problem.

Ans.

Reversing two halves of a linked list problem

  • Identify input and output linked lists

  • Reverse the two halves of the input linked list

  • Compare the reversed input linked list with the output linked list

  • If they match, return true else false

Add your answer
right arrow
Asked in
SDE Interview

Q18. What happens when we type amazon.com ?

Ans.

Typing amazon.com in the browser's address bar takes you to Amazon's website.

  • The browser sends a request to the DNS server to resolve the domain name 'amazon.com' to an IP address.

  • The browser establishes a TCP connection with the server at the resolved IP address.

  • The browser sends an HTTP request to the server for the homepage of Amazon's website.

  • The server responds with the HTML code for the homepage, which the browser renders and displays to the user.

Add your answer
right arrow
Asked in
SDE Interview

Q19. Find the second largest element in an array. (-----/)

Ans.

Find the second largest element in an array.

  • Sort the array and return the second last element

  • Iterate through the array and keep track of the two largest elements

  • Use a priority queue to find the second largest element

Add your answer
right arrow
Asked in
SDE Interview

Q20. Find top 10 trending words inserted by users in sites like twitter. Only algorithm

Ans.

An algorithm to find top 10 trending words inserted by users in sites like Twitter.

  • Collect a large dataset of tweets

  • Tokenize the tweets into individual words

  • Remove stop words and punctuation

  • Count the frequency of each word

  • Sort the words by frequency in descending order

  • Select the top 10 words

Add your answer
right arrow
Asked in
SDE Interview

Q21. write an efficient code to find the first occurrence of 1 in a sorted binary array

Ans.

Find the first occurrence of 1 in a sorted binary array.

  • Use binary search to find the first occurrence of 1.

  • If the mid element is 1, check if it's the first occurrence or if the element before it is 0.

  • If the mid element is 0, search in the right half of the array.

  • If the mid element is 1 and the element before it is also 1, search in the left half of the array.

Add your answer
right arrow
Asked in
SDE Interview

Q22. A sliding window problem where we had to minimise the partial sum of the array.

Ans.

Sliding window problem to minimize partial sum of array.

  • Use two pointers to maintain the window.

  • Move the right pointer to expand the window and left pointer to shrink it.

  • Keep track of the minimum partial sum seen so far.

  • Example: Given array [2, 3, 1, 2, 4, 3] and window size 3, the minimum partial sum is 6.

Add your answer
right arrow
Asked in
SDE Interview

Q23. What is the meaning of memory leakage?

Ans.

Memory leakage is a situation where a program fails to release memory it no longer needs.

  • Memory leakage can cause a program to slow down or crash due to insufficient memory.

  • It is caused by programming errors such as not freeing allocated memory or losing references to it.

  • Examples include forgetting to close a file or database connection, or not releasing memory allocated for a variable.

  • Memory leakage can be detected using memory profiling tools.

  • Preventing memory leakage invol...read more

Add your answer
right arrow
Asked in
SDE Interview

Q24. Given a tree populate the sibiling of the tree node with the next node in same level.space complexity-O(1)

Ans.

Populate sibling of a tree node with next node in same level with O(1) space complexity.

  • Traverse the tree level by level using BFS.

  • For each node, check if it has a sibling to its right.

  • If yes, populate the sibling pointer of the current node with the right sibling.

  • If no, move to the next level.

  • Repeat until all levels are traversed.

Add your answer
right arrow
Asked in
SDE Interview

Q25. ind the first occurrence of 1 in a sorted infinite binary tree

Ans.

Find the first occurrence of 1 in a sorted infinite binary tree.

  • Use binary search to traverse the tree.

  • If the current node is 1, check if its left child is also 1. If yes, move to the left subtree, else return the current node.

  • If the current node is 0, move to the right subtree.

  • Repeat until the first occurrence of 1 is found or the tree is exhausted.

Add your answer
right arrow
Asked in
SDE Interview

Q26. Design a valet parking lot with basic use-case of assigning ticket to customer and retrieving the car later. Three sizes available. Use best fit and nearest distance

Ans.

Design a valet parking lot with ticket assignment and car retrieval using best fit and nearest distance.

  • Create a parking lot with designated spots for each size of car

  • Assign a ticket to the customer upon entry and record the spot number

  • Retrieve the car by searching for the nearest available spot of the appropriate size

  • Use best fit algorithm to minimize empty spots

  • Implement a system for payment upon exit

Add your answer
right arrow
Asked in
SDE Interview

Q27. Given a tree construct a mirror tree and return root of mirror tree

Ans.

Construct a mirror tree from a given tree and return the root of the mirror tree.

  • Traverse the given tree in a recursive manner.

  • Swap the left and right child of each node.

  • Return the root of the mirror tree.

Add your answer
right arrow
Asked in
SDE Interview

Q28. Remove duplicated from a string in O(n) without using hash

Ans.

Remove duplicates from a string in O(n) without using hash

  • Use an array of boolean values to keep track of characters already seen

  • Iterate through the string and mark characters as seen in the array

  • If a character has already been seen, remove it from the string

Add your answer
right arrow
Asked in
SDE Interview

Q29. What happens when you type amazon.com in browser

Ans.

When you type amazon.com in a browser, it sends a request to the Amazon servers, which then respond by sending back the website's content to be displayed on your screen.

  • Browser sends a DNS request to resolve the domain name 'amazon.com' to an IP address

  • Browser establishes a TCP connection with the Amazon servers

  • Browser sends an HTTP request to the Amazon servers for the website content

  • Amazon servers process the request and send back the website content

  • Browser renders the webs...read more

Add your answer
right arrow
Asked in
SDE Interview

Q30. Find top 10 selling product given the count of sales of each product

Ans.

To find the top 10 selling products, sort the products by their sales count in descending order and select the first 10.

  • Sort the products by their sales count in descending order

  • Select the first 10 products from the sorted list

Add your answer
right arrow
Asked in
SDE Interview

Q31. Given a stack output a sorted stack.(hint use recursion)

Ans.

Sort a stack using recursion.

  • Pop the top element from the stack and recursively sort the remaining stack.

  • Insert the popped element in the correct position in the sorted stack.

  • Repeat until the entire stack is sorted.

  • Use a helper function to insert the element in the correct position.

  • Time complexity: O(n^2), space complexity: O(n) due to recursion.

  • Example: Input stack - [5, 2, 7, 1], Output stack - [1, 2, 5, 7]

Add your answer
right arrow
Asked in
SDE Interview

Q32. Describe ACID properties in detail

Ans.

ACID properties ensure reliability and consistency in database transactions.

  • ACID stands for Atomicity, Consistency, Isolation, and Durability.

  • Atomicity ensures that a transaction is treated as a single unit of work, either all or none of its operations are executed.

  • Consistency ensures that a transaction brings the database from one valid state to another.

  • Isolation ensures that concurrent transactions do not interfere with each other, providing a sense of isolation.

  • Durability ...read more

Add your answer
right arrow
Asked in
SDE Interview

Q33. Print a matrix diagonally. (-----/)

Ans.

Print a matrix diagonally.

  • Start from the top left corner and print the diagonal elements

  • Move down and right to print the next diagonal

  • Repeat until all diagonals are printed

Add your answer
right arrow
Asked in
SDE Interview

Q34. DFS of binary tree, n-ary tree

Ans.

DFS is a traversal algorithm used to visit all nodes of a tree or graph. It can be applied to binary as well as n-ary trees.

  • DFS stands for Depth First Search.

  • In DFS, we start from the root node and visit its children recursively until we reach a leaf node.

  • There are two types of DFS: Preorder (root, left, right) and Postorder (left, right, root).

  • DFS can be implemented using recursion or a stack data structure.

  • Example: In a binary tree with nodes 1, 2, 3, 4, 5, 6, 7, a preorder...read more

Add your answer
right arrow
Asked in
SDE Interview

Q35. Find 2nd min element from given array

Ans.

Find the 2nd minimum element from an array.

  • Sort the array and return the second element.

  • Use a loop to find the minimum and second minimum elements.

  • Initialize two variables to store the minimum and second minimum elements.

Add your answer
right arrow
Asked in
SDE Interview

Q36. Level order traversal of a tree

Ans.

Level order traversal of a tree is a method to visit all the nodes of a tree level by level.

  • Use a queue to store the nodes of the tree

  • Start with the root node and enqueue it

  • While the queue is not empty, dequeue a node and visit it

  • Enqueue the left and right child of the visited node if they exist

  • Repeat until all nodes are visited

Add your answer
right arrow
Asked in
SDE Interview

Q37. FIND THE LOOP IN LINKED LIST

Ans.

To find a loop in a linked list, use Floyd's Tortoise and Hare algorithm.

  • Use two pointers, slow and fast, to traverse the linked list.

  • If there is a loop, the two pointers will eventually meet at the same node.

  • To find the start of the loop, reset one pointer to the head and move both pointers at the same pace.

Add your answer
right arrow
Asked in
SDE Interview

Q38. Advantages of heaps over arrays

Ans.

Heaps allow efficient insertion and deletion of elements, unlike arrays.

  • Heaps are useful for implementing priority queues.

  • Insertion and deletion of elements in a heap take O(log n) time, while in an array it takes O(n) time.

  • Heaps are dynamically resizable, unlike arrays which have a fixed size.

  • Heaps can be used to efficiently find the kth largest/smallest element in an array.

  • Examples of heap data structures include binary heaps, Fibonacci heaps, and pairing heaps.

Add your answer
right arrow
Asked in
SDE Interview

Q39. 1 hard array problem and internship experience

Ans.

I solved a hard array problem during my internship and gained valuable experience.

  • During my internship, I was tasked with optimizing a program that involved manipulating arrays of strings.

  • I used various data structures and algorithms to efficiently solve the problem, such as hash maps and sorting techniques.

  • One specific example of a hard array problem I worked on was implementing a word search algorithm using a 2D array of characters.

Add your answer
right arrow
Asked in
SDE Interview

Q40. Angular JS and React JS difference

Ans.

Angular JS is a full-fledged framework while React JS is a library for building user interfaces.

  • Angular JS is a full-fledged MVC framework with two-way data binding, while React JS is a library for building user interfaces using components.

  • Angular JS uses HTML templates with additional markup, while React JS uses JSX for rendering components.

  • Angular JS has a steep learning curve due to its complexity, while React JS is easier to learn and use.

  • Angular JS has a larger ecosystem...read more

Add your answer
right arrow
Asked in
SDE Interview

Q41. Find the optimal cost while combining the ropes

Ans.

Combine ropes to minimize cost by always combining the two shortest ropes

  • Sort the ropes in ascending order

  • Combine the two shortest ropes at each step

  • Update the cost and add the new combined rope back to the list

  • Repeat until only one rope is left

Add your answer
right arrow
Asked in
SDE Interview

Q42. Modified version of Knapsack problem

Ans.

Modified Knapsack problem

  • Similar to Knapsack problem, but with additional constraints or modifications

  • May involve multiple knapsacks or fractional items

  • Examples include 0/1 Knapsack with profit and weight limits, bounded Knapsack with item quantity limits

Add your answer
right arrow
Asked in
SDE Interview

Q43. How you handle pressure

Ans.

I handle pressure by staying organized, prioritizing tasks, and taking breaks when needed.

  • I prioritize tasks based on deadlines and importance

  • I break down large tasks into smaller, manageable steps

  • I communicate with team members or supervisors if feeling overwhelmed

  • I practice mindfulness techniques like deep breathing or meditation to stay calm

Add your answer
right arrow
Asked in
SDE Interview

Q44. CREATE A LINKED LIST

Ans.

A linked list is a data structure consisting of nodes where each node points to the next node in the sequence.

  • Create a Node class with data and next pointer

  • Initialize a head pointer to null

  • Add nodes by updating next pointers

Add your answer
right arrow
Asked in
SDE Interview

Q45. Spring is immutable or mutable

Ans.

Spring is immutable

  • Spring framework is immutable

  • Once a Spring bean is created, its state cannot be changed

  • Any modifications to a Spring bean result in a new instance being created

Add your answer
right arrow
Asked in
SDE Interview

Q46. Explain the bigO of OA

Ans.

BigO of OA refers to the time complexity analysis of the algorithm OA.

  • BigO notation is used to describe the worst-case time complexity of an algorithm.

  • It provides an upper bound on the growth rate of the algorithm's time complexity as the input size increases.

  • For example, if an algorithm has a time complexity of O(n^2), it means that the algorithm's running time grows quadratically with the input size.

Add your answer
right arrow
Asked in
SDE Interview

Q47. Graphs with BFS, DFS

Ans.

BFS and DFS are algorithms used to traverse graphs.

  • BFS (Breadth-First Search) explores all neighbor nodes at the present depth prior to moving on to nodes at the next depth level.

  • DFS (Depth-First Search) explores as far as possible along each branch before backtracking.

  • BFS uses a queue data structure, while DFS uses a stack or recursion.

  • Example: BFS can be used to find the shortest path in an unweighted graph, while DFS can be used to detect cycles in a graph.

Add your answer
right arrow

More about working at Amazon

Back
Awards Leaf
AmbitionBox Logo
Top Rated Mega Company - 2024
Awards Leaf
Awards Leaf
AmbitionBox Logo
Top Rated Company for Women - 2024
Awards Leaf
Awards Leaf
AmbitionBox Logo
Top Rated Internet/Product Company - 2024
Awards Leaf
Contribute & help others!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos

Interview Process at Amazon SDE

based on 35 interviews
4 Interview rounds
Coding Test Round - 1
Technical Round - 1
Coding Test Round - 2
Technical Round - 2
View more
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

Top SDE Interview Questions from Similar Companies

Microsoft Corporation Logo
4.0
 • 14 Interview Questions
Facebook Logo
4.3
 • 14 Interview Questions
View all
Recently Viewed
LIST OF COMPANIES
Discover companies
Find best workplace
LIST OF COMPANIES
Discover companies
Find best workplace
LIST OF COMPANIES
Discover companies
Find best workplace
REVIEWS
Amazon
No Reviews
REVIEWS
Amazon
No Reviews
SALARIES
Viacom18 Media
No Salaries
COMPANY BENEFITS
Viacom18 Media
No Benefits
INTERVIEWS
Amazon
No Interviews
SALARIES
Zee Entertainment Enterprises
No Salaries
INTERVIEWS
Ramoji Film City
No Interviews
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
75 Lakh+

Reviews

5 Lakh+

Interviews

4 Crore+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter