Amazon Theoretical Interview Questions

Last Updated : 28 Jul, 2026

Amazon's interview process is designed to assess a candidate's problem-solving ability, technical knowledge, and leadership qualities through coding, system design, OOPs, and behavioral interviews. Preparing the most frequently asked questions can help you perform confidently in every interview round.

  • Covers 25 commonly asked Amazon interview questions with concise and interview-focused answers.
  • Includes questions from Data Structures and Algorithms (DSA), System Design, and Object-Oriented Programming (OOPs).

1. How Does HashMap Work Internally?

HashMap is a data structure that stores key-value pairs and provides average O(1) time complexity for insertion, deletion, and retrieval. It uses an array of buckets, hashing, and linked lists or red-black trees to efficiently store and access data.

  • Compute the hash code of the key using the hashCode() method.
  • Convert the hash code into a bucket index.
  • Store the key-value pair in the corresponding bucket.
  • If multiple keys map to the same bucket (collision), store them using a linked list or a red-black tree (Java 8+).
  • During retrieval, calculate the bucket index again and compare keys using the equals() method to find the correct value.

2. What are the Four Pillars of Object-Oriented Programming?

The four pillars of Object-Oriented Programming (OOP) are the fundamental principles used to design modular, reusable, and maintainable software.

The Four Pillars:

  • Encapsulation: Bundles data and methods into a single class while restricting direct access to data.
  • Abstraction: Hides implementation details and exposes only the essential functionality.
  • Inheritance: Allows one class to inherit the properties and behavior of another class.
  • Polymorphism: Enables the same interface or function to behave differently for different objects.

3. What is Load Balancing, and Why Is It Important in System Design?

Load balancing is the process of distributing incoming requests across multiple servers to ensure that no single server becomes overloaded. It improves system performance, availability, and scalability by efficiently utilizing server resources.

  • Improves scalability by distributing traffic across multiple servers, allowing the system to handle more users.
  • Ensures high availability by redirecting requests to healthy servers if one server fails.
  • Enhances performance by preventing server overload and reducing response time.

4. What is the Difference Between Abstraction and Encapsulation?

Both abstraction and encapsulation are core OOP concepts, but they serve different purposes.

AbstractionEncapsulation
Hides implementation details from the user.Hides data by restricting direct access.
Focuses on what an object does.Focuses on how data is protected.
Achieved using abstract classes and interfaces.Achieved using access specifiers (private, protected, public).

5. What is Recursion, and When Should It Be Used?

Recursion is a programming technique in which a function calls itself to solve a problem by breaking it into smaller subproblems.

Common Use Cases:

  • Tree and graph traversals.
  • Backtracking problems such as N-Queens and Sudoku.
  • Divide and conquer algorithms like Merge Sort and Quick Sort.

6. How do you detect a cycle in a linked list?

A cycle exists in a linked list if a node is reachable again by continuously following the next pointers. The most efficient way to detect a cycle is Floyd's Cycle Detection Algorithm (Tortoise and Hare Algorithm).

Approach:

  • Use two pointers: slow and fast.
  • Move slow one node at a time and fast two nodes at a time.
  • If the two pointers meet, a cycle exists.
  • If fast or fast->next becomes NULL, the list has no cycle.

7. What is Polymorphism?

Polymorphism is an OOP concept that allows the same function or interface to perform different actions depending on the object that invokes it.

Types of Polymorphism:

  • Compile-time Polymorphism: Achieved through function or operator overloading.
  • Run-time Polymorphism: Achieved through method overriding using virtual functions.

8. What is Caching, and Where Is It Used?

Caching is the process of storing frequently accessed data in a fast storage layer so that future requests can be served more quickly.

  • Reduces response time for repeated requests.
  • Decreases the load on databases and servers.
  • Improves the overall performance of the system.

9. How can you find the middle element of a linked list?

The middle element of a linked list can be found efficiently using the two-pointer (slow and fast pointer) technique. The slow pointer moves one node at a time, while the fast pointer moves two nodes at a time. When the fast pointer reaches the end, the slow pointer points to the middle node.

Approach:

  • Initialize two pointers: slow and fast at the head.
  • Move slow by one node and fast by two nodes.
  • When fast reaches the end, slow points to the middle node.

10. What is Inheritance, and What Are Its Advantages?

Inheritance is an OOP concept that allows a class to acquire the properties and methods of another class. It promotes code reuse and establishes an "is-a" relationship between classes.

Advantages:

  • Promotes code reuse by inheriting existing features.
  • Reduces code duplication and improves maintainability.
  • Makes it easier to extend existing classes.
  • Supports hierarchical relationships between classes.

11. What is Database Sharding?

Database sharding is a technique of splitting a large database into multiple smaller databases, called shards, where each shard stores a portion of the data.

  • Improves scalability by distributing data across multiple servers.
  • Reduces query load on a single database.
  • Supports high-performance applications with large datasets.

12. What is the Difference Between BFS and DFS, and When Would You Use Each?

Breadth First Search (BFS) explores nodes level by level, whereas Depth First Search (DFS) explores as far as possible along one path before backtracking. These are the key difference.

FeatureBFSDFS
Traversal OrderLevel by levelDepth first
Data StructureQueueStack / Recursion
Shortest PathFinds shortest path in an unweighted graphDoes not guarantee the shortest path
Space ComplexityO(V)O(V)

Use BFS when:

  • Finding the shortest path in an unweighted graph.
  • Level-order traversal of trees.
  • Finding the minimum number of steps between nodes.

Use DFS when:

  • Detecting cycles in a graph.
  • Topological sorting.
  • Solving backtracking problems such as maze traversal.

13. What is the Difference Between Method Overloading and Method Overriding?

Both method overloading and method overriding support polymorphism, but they differ in when and how they are implemented.

Method OverloadingMethod Overriding
Occurs within the same class.Occurs between a base and derived class.
Methods have the same name but different parameters.The derived class redefines a base class method with the same signature.
Achieves compile-time polymorphism.Achieves run-time polymorphism.

14. What is Replication in Databases?

Database replication is the process of creating and maintaining copies of the same database on multiple servers to improve availability, reliability, and fault tolerance.

  • Improves data availability and fault tolerance.
  • Distributes read requests across multiple servers.
  • Provides backup in case the primary database fails.

15. How do you find the kth largest element in an array?

The kth largest element is the element that would appear at position k if the array were sorted in descending order. It can be found efficiently using a min-heap of size k or the Quickselect algorithm.

Approach:

  • Maintain a min-heap of the first k elements.
  • Traverse the remaining elements.
  • Replace the heap's top if the current element is larger.
  • The heap's top is the kth largest element.

16. Explain Horizontal Scaling and Vertical Scaling.

Scaling is the process of increasing a system's capacity to handle more users or workload. It can be achieved by adding more resources (horizontal scaling) or by upgrading existing resources (vertical scaling).

Horizontal ScalingVertical Scaling
Adds more servers to the system.Upgrades the existing server (CPU, RAM, Storage).
Also known as scale-out.Also known as scale-up.
Provides better fault tolerance and availability.Limited by the maximum capacity of a single server.
Suitable for large-scale distributed applications.Suitable for small to medium workloads.

17. How would you merge two sorted arrays efficiently?

Two sorted arrays can be merged efficiently using the two-pointer technique. Compare the current elements of both arrays and insert the smaller one into the result array until all elements are processed.

Approach:

  • Initialize one pointer for each array.
  • Compare the current elements.
  • Insert the smaller element into the result array.
  • Copy the remaining elements after one array is exhausted.

18. What is the CAP Theorem?

The CAP Theorem states that a distributed system can guarantee only two out of the following three properties at the same time: Consistency (C), Availability (A), and Partition Tolerance (P).

CAP Properties:

  • Consistency (C): Every user sees the same, up-to-date data.
  • Availability (A): Every request receives a response, even if some data is outdated.
  • Partition Tolerance (P): The system works even if servers lose communication.

19. How do you determine whether a binary tree is balanced?

A binary tree is balanced if, for every node, the difference between the heights of its left and right subtrees is at most 1. This can be checked efficiently using a recursive height calculation.

Approach:

  • Recursively calculate the height of the left and right subtrees.
  • Check if their height difference is greater than 1.
  • Repeat the process for every node.
  • If all nodes satisfy the condition, the tree is balanced.

20. How would you design a URL Shortening Service?

A URL shortening service converts a long URL into a short, unique URL that redirects users to the original link. The system should be scalable, reliable, and capable of handling a large number of requests.

Working:

  • The user submits a long URL to the application.
  • A load balancer forwards the request to an application server.
  • The server generates a unique short code for the URL.
  • The URL mapping is stored in the database.
  • Frequently accessed mappings are stored in the cache.
  • The generated short URL is returned to the user.
  • On access, the service retrieves the original URL and redirects the user.

21. How can you implement an LRU Cache efficiently?

An LRU (Least Recently Used) Cache stores a fixed number of items and removes the least recently accessed item when the cache reaches its capacity. It can be efficiently implemented using a Hash Map and a Doubly Linked List.

Approach:

  • Use a hash map to store keys and their corresponding nodes.
  • Use a doubly linked list to maintain the order of usage.
  • Move accessed items to the front of the list.
  • Remove the last node when the cache exceeds its capacity.

22. How would you design a Notification System?

A notification system delivers messages such as emails, SMS, or push notifications to users in a reliable and scalable manner. It should support high throughput, retries, and multiple delivery channels.

Working:

  • The application sends a notification request to the server.
  • A load balancer routes the request to a notification service.
  • The service places the request into a message queue.
  • Worker servers process queued notifications asynchronously.
  • Notifications are delivered through Email, SMS, or Push providers.
  • Delivery status is stored in a database for tracking.
  • Failed notifications are retried automatically if needed.

23. How would you find the longest substring without repeating characters?

The longest substring without repeating characters can be found efficiently using the sliding window technique. Maintain a window of unique characters and expand or shrink it as needed when duplicates are encountered.

Approach:

  • Use two pointers to represent the current window.
  • Store the last occurrence of each character using a hash map.
  • Move the left pointer whenever a duplicate is found.
  • Keep track of the maximum window length.

24. Why are Message Queues Used in Distributed Systems?

A message queue is used in distributed systems to enable asynchronous communication between services. It helps decouple components, improve scalability, and ensure reliable message delivery.

  • Handles traffic spikes by buffering incoming requests.
  • Enables asynchronous processing of time-consuming tasks.
  • Improves reliability through retries and message persistence.

25. What is Dynamic Programming, and When Should It Be Used?

Dynamic Programming (DP) is an optimization technique used to solve problems by breaking them into smaller overlapping subproblems and storing their results to avoid repeated computations. Use Dynamic Programming when:

  • The problem has overlapping subproblems.
  • It exhibits optimal substructure.
  • The same subproblems are solved multiple times.
Comment