DSA / Hashmaps Interview Questions 2026

Published July 22, 2026 · Updated July 22, 2026

72 DSA / Hashmaps interview questions from PayU, Amazon, TCS, Google, Microsoft, Grab and more. Real questions from Technical, System Design, and HR rounds.

72 questions
Companies: PayU, Amazon, TCS, Google…

All DSA / Hashmaps Questions

TCS Easy Technical round 1-3 years

Implement a function that checks if a string of brackets is valid. Brackets: (), [], {}. Must handle nested brackets.

↑ 84 upvotes · 32 engineers asked this · SDE1
PayU Medium Technical round 2–5 YearsInterview ExperienceJavaScript

Design an in-memory rate limiter that allows at most N requests per user per minute. Given a stream of {userId, timestamp} requests, return true if the request should be allowed or false if it should be throttled. Implement using JavaScript.

↑ 83 upvotes · 58 engineers asked this · Full Stack Developer
Amazon Medium Technical round 2-4 years

Given an array of intervals, merge all overlapping intervals. Return the minimum number of intervals after merging. Example: [[1,3],[2,6],[8,10],[15,18]] → [[1,6],[8,10],[15,18]]

↑ 83 upvotes · 31 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Implement an LRU (Least Recently Used) cache with O(1) get and O(1) put. Explain why a naive HashMap alone doesn't solve this.

↑ 82 upvotes · 30 engineers asked this · SDE2
Amazon Hard Scenario round 4-8 years

You have a log file where each line has a timestamp and user ID. Find the K users who appear most frequently in the last N minutes. The file is 100GB and is being written to in real-time.

↑ 81 upvotes · 29 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Design a data structure that supports push, pop, and getMin in O(1) time and O(1) space (beyond the stack itself).

↑ 80 upvotes · 28 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Given a binary tree, find the longest path between any two nodes (not necessarily through root). You have 30 minutes.

↑ 79 upvotes · 27 engineers asked this · SDE2
Amazon Hard Technical round 4-7 years

You're implementing a rate limiter using a sliding window algorithm. Given a stream of timestamps (Unix milliseconds), return true if a request is within the limit of 100 requests per minute. The stream can have 1 billion events.

↑ 78 upvotes · 26 engineers asked this · SDE2
Amazon Medium Technical round 2-4 years

Given a binary tree, check if it's a valid Binary Search Tree. Consider all possible edge cases.

↑ 78 upvotes · 16 engineers asked this · SDE2
Amazon Hard Technical round 2-5 years

You have a function that runs in O(n²) time and your interviewer says 'this is too slow for n=10 million.' The function finds all pairs of numbers in an array that sum to a target. Optimize it to O(n).

↑ 77 upvotes · 25 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Implement a min-heap data structure from scratch. Show insert and extractMin operations.

↑ 77 upvotes · 15 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Design an algorithm to find the shortest path through a maze represented as a 2D grid. 0 = open, 1 = wall. Start at top-left, end at bottom-right.

↑ 76 upvotes · 14 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Find the first missing positive integer in an unsorted array. Must be O(n) time and O(1) extra space.

↑ 75 upvotes · 13 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Implement a stack using only two queues. Then implement a queue using only two stacks.

↑ 74 upvotes · 12 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Given an array of n integers, find all triplets that sum to zero. Remove duplicates from the result.

↑ 73 upvotes · 11 engineers asked this · SDE2
PayU Medium Technical round 2–5 YearsInterview ExperienceJavaScript

Implement a function that detects duplicate transaction IDs within a 5-minute time window. Given an array of {id, timestamp} objects, return all IDs that appear more than once within any 5-minute rolling window. What data structure would you use and why?

↑ 72 upvotes · 51 engineers asked this · Full Stack Developer
TCS Easy Technical round 1-4 years

Given a string with brackets, check if it's valid. Valid: every open bracket has a matching close bracket in correct order.

↑ 61 upvotes · 29 engineers asked this · SDE2
TCS Medium Technical round 2-5 years

Implement merge sort and explain its advantages over quicksort.

↑ 60 upvotes · 28 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Implement binary search on a rotated sorted array (e.g., [4,5,6,7,0,1,2]).

↑ 59 upvotes · 27 engineers asked this · SDE2
TCS Easy Technical round 1-3 years

Write a function that checks if two strings are anagrams of each other. Handle Unicode characters.

↑ 58 upvotes · 26 engineers asked this · SDE1
PayU Medium Technical round 2–5 YearsInterview ExperienceJavaScriptJava

Given a list of payment events, each with a merchant ID and an amount, use a HashMap to return the top 3 merchants by total transaction volume. How would you handle ties? Write the complete solution.

↑ 57 upvotes · 39 engineers asked this · Full Stack Developer
Amazon Medium Technical round 2-5 years

Given a binary tree, return the level-order traversal as a list of lists.

↑ 57 upvotes · 25 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Write a function to detect if a linked list has a cycle. Can you do it without extra space?

↑ 56 upvotes · 24 engineers asked this · SDE2
Google Hard System Design round 4-7 years

How would you design and implement an autocomplete system? Focus on the data structure and ranking.

↑ 56 upvotes · 34 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Implement a stack that supports push, pop, top, and getMin in O(1) time.

↑ 55 upvotes · 23 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Write a function to compute the power set (all subsets) of a given set.

↑ 55 upvotes · 33 engineers asked this · SDE2
TCS Easy Technical round 1-4 years

Given an array of integers, find two numbers that sum to a target. Optimize for O(n) time and O(n) space.

↑ 54 upvotes · 22 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Implement a function that finds the longest common subsequence (LCS) of two strings.

↑ 54 upvotes · 32 engineers asked this · SDE2
Amazon Hard Technical round 2-6 years

Implement LRU Cache with O(1) get and put operations.

↑ 53 upvotes · 21 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Given a 2D grid, find the shortest path from start to end avoiding obstacles.

↑ 53 upvotes · 31 engineers asked this · SDE2
Amazon Hard Technical round 2-6 years

Write a function to find the longest palindromic substring in a string. What is the optimal approach?

↑ 52 upvotes · 20 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Explain and implement the Dutch National Flag algorithm for sorting an array with only 3 distinct values.

↑ 52 upvotes · 30 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Write a function to find all valid parentheses combinations for n pairs.

↑ 51 upvotes · 29 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Implement topological sort on a directed acyclic graph (DAG). What's the real-world use case?

↑ 50 upvotes · 28 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Given a string, find the length of the longest substring without repeating characters.

↑ 49 upvotes · 27 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Write a function to check if a binary tree is a valid Binary Search Tree (BST).

↑ 48 upvotes · 26 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Implement a min-heap from scratch. What are the time complexities of insert and extractMin?

↑ 47 upvotes · 25 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Given an array, find the maximum sum subarray (Kadane's algorithm). Explain the dynamic programming insight.

↑ 46 upvotes · 24 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Write an algorithm to serialize and deserialize a binary tree.

↑ 45 upvotes · 23 engineers asked this · SDE2
Amazon Medium Technical round 2-4 years

Given an array, find the maximum sum of a subarray (Kadane's algorithm). Then extend: return the actual subarray indices, not just the sum.

↑ 44 upvotes · 52 engineers asked this · SDE2
Amazon Medium Technical round 3-6 years

Implement a Trie (prefix tree) with insert, search, and startsWith methods.

↑ 44 upvotes · 22 engineers asked this · SDE2
Amazon Hard Technical round 4-7 years

Design a data structure for a phone directory that supports: addNumber, removeNumber, getAny (return any available number). All operations O(1).

↑ 43 upvotes · 51 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Given a matrix of 0s and 1s, find the number of islands (connected components of 1s).

↑ 43 upvotes · 21 engineers asked this · SDE2
Amazon Hard Technical round 4-7 years

Given a string, find the minimum number of characters to insert to make it a palindrome.

↑ 42 upvotes · 50 engineers asked this · SDE2
Amazon Hard Technical round 2-6 years

Implement a function to find the kth largest element in an unsorted array. Optimize for O(n) average case.

↑ 42 upvotes · 20 engineers asked this · SDE2
Microsoft Medium Technical round 2-5 yearsJavaC++

Design a data structure that supports insert, delete, and getRandom in O(1) average time. Walk through your approach.

↑ 42 upvotes · 33 engineers asked this · Senior SDE
TCS Easy Technical round 1-3 years

Implement a function to check if a number is a power of 2 without using loops or recursion.

↑ 41 upvotes · 49 engineers asked this · SDE1
Amazon Hard Technical round 4-7 years

You have N tasks, each with a deadline and profit. You can do at most one task per unit of time. Maximize total profit. (Job Scheduling with deadlines)

↑ 40 upvotes · 48 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Implement Dijkstra's algorithm for shortest path. A city has 1000 nodes and 5000 edges. What data structure gives best performance?

↑ 39 upvotes · 47 engineers asked this · SDE2
Amazon Hard Technical round 4-7 years

Given a matrix of 0s and 1s, find the largest rectangle containing only 1s.

↑ 38 upvotes · 46 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Implement a function that, given an integer n, returns all valid combinations of n pairs of parentheses.

↑ 37 upvotes · 45 engineers asked this · SDE2
Amazon Hard Technical round 4-7 years

You have a stream of integers. At any point, you can be asked for the median. Implement a data structure that supports add(num) in O(log n) and getMedian() in O(1).

↑ 36 upvotes · 44 engineers asked this · SDE2
Amazon Hard Technical round 4-7 years

Find the longest increasing subsequence in an array. Must be O(n log n).

↑ 35 upvotes · 43 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Implement a function to serialize and deserialize a binary tree. The serialized format must allow perfect reconstruction.

↑ 34 upvotes · 42 engineers asked this · SDE2
Amazon Medium Technical round 2-4 years

Given a list of intervals sorted by start time, insert a new interval and merge if necessary. Return the updated list.

↑ 33 upvotes · 41 engineers asked this · SDE2
TCS Medium Technical round 1-4 years

Implement a function to check if two strings are anagrams of each other. Then solve for: given a string and a pattern, find all anagram substrings.

↑ 32 upvotes · 40 engineers asked this · SDE2
Amazon Hard Technical round 4-7 years

You have a graph of cities with flight prices between them. Find the cheapest flight from source to destination with at most K stops.

↑ 31 upvotes · 39 engineers asked this · SDE2
TCS Medium Screening round 2-5 years

How does quicksort choose a pivot and what makes it O(n²) in the worst case?

↑ 31 upvotes · 39 engineers asked this · SDE2
Amazon Hard Technical round 3-5 years

Implement a function that returns all permutations of a string. If string has duplicates, return unique permutations only.

↑ 30 upvotes · 38 engineers asked this · SDE2
TCS Medium Technical round 2-5 years

Write a function to validate if a given string is a valid IP address (both IPv4 and IPv6).

↑ 30 upvotes · 38 engineers asked this · SDE2
Amazon Medium Technical round 2-4 years

Given an m x n grid of integers, find the path from top-left to bottom-right that maximizes the sum. You can only move right or down.

↑ 29 upvotes · 37 engineers asked this · SDE2
TCS Medium Screening round 2-5 years

Explain the time and space complexity of hash table operations. What happens when load factor is too high?

↑ 29 upvotes · 37 engineers asked this · SDE2
Google Hard Technical round 6-10 yearsSystem DesignGo

Given a large dependency graph of build targets, design an algorithm to compute the minimal set of targets that need to be rebuilt after a file changes, and explain how you would parallelize the rebuild across workers respecting dependency order.

↑ 29 upvotes · 11 engineers asked this · Staff Engineer
Google Hard Technical round 3-6 years

Implement a trie data structure. Your implementation must support: insert, search, and startsWith. Then optimize space for a dictionary with 1 million words.

↑ 28 upvotes · 36 engineers asked this · SDE2
TCS Medium Screening round 2-5 years

What is the difference between DFS and BFS? When does each find the optimal solution?

↑ 28 upvotes · 36 engineers asked this · SDE2
Amazon Hard Technical round 4-7 years

You have an array of stock prices. Find the maximum profit from at most 2 transactions (buy-sell cycles). You must sell before buying again.

↑ 27 upvotes · 35 engineers asked this · SDE2
Amazon Hard Technical round 3-6 years

Implement Dijkstra's shortest path algorithm. What graph type is it NOT suitable for?

↑ 27 upvotes · 35 engineers asked this · SDE2
Amazon Medium Technical round 2-5 years

Given a binary search tree, find the k-th smallest element. Can you do it without building a sorted array?

↑ 26 upvotes · 34 engineers asked this · SDE2
Amazon Medium Technical round 2-4 years

Implement a function to detect a cycle in a linked list. What is Floyd's cycle detection algorithm and why is it O(1) space?

↑ 25 upvotes · 33 engineers asked this · SDE2
Grab Medium Technical round 2-5 yearsJavaPython

Given an array of ride fare amounts collected over a day, find the maximum sum of any contiguous subarray of exactly k rides (a sliding window problem). Walk through the O(n) approach.

↑ 25 upvotes · 17 engineers asked this · Senior SDE
TCS Medium Technical round 2-4 years

Given a string, find the length of the longest substring without repeating characters. 'abcabcbb' → 3 ('abc').

↑ 6 upvotes · 34 engineers asked this · SDE2
Amazon Hard Technical round 4-7 years

Find the median of a stream of numbers. Numbers arrive one at a time. After each addition, you must be able to return the current median in O(log n) time.

↑ 5 upvotes · 33 engineers asked this · SDE2

Practice these questions with AI feedback

Get instant grading on your answers, identify your weak areas, and generate a personalised 14-day study plan — all free.

Build my study plan →

Same topic at specific companies

PayU DSA / Hashmaps Amazon DSA / Hashmaps TCS DSA / Hashmaps Google DSA / Hashmaps Microsoft DSA / Hashmaps Grab DSA / Hashmaps

Related topics

DSA / Arrays System Design DSA / Trees DSA / Graphs Behavioral Testing Domain DevOps API Testing GCP / Real-time Data Java / Pub-Sub React / Performance Node.js / Memory SQL / Query Optimization Python / Async AWS / Lambda Kafka / Consumer Microservices / Saga Pattern TypeScript / Type System MongoDB / Indexing Security / SQL Injection Performance / Latency Tail Redis / Cache Stampede Elasticsearch / Cluster Health GraphQL / Security Data Engineering / Exactly Once Snowflake / Architecture PySpark / Core Concepts Airflow / Scheduling Web / WebAssembly Debugging / Production JavaScript / V8 Engine

Frequently asked questions

Implement a function that checks if a string of brackets is valid. Brackets: (), [], {}. Must handle nested brackets.
Implement a function that checks if a string of brackets is valid. Brackets: (), [], {}. Must handle nested brackets.
Design an in-memory rate limiter that allows at most N requests per user per minute. Given a stream of {userId, timestamp} requests, return true if the request should be allowed or false if it should be throttled. Implement using JavaScript.
Design an in-memory rate limiter that allows at most N requests per user per minute. Given a stream of {userId, timestamp} requests, return true if the request should be allowed or false if it should be throttled. Implement using JavaScript.
Given an array of intervals, merge all overlapping intervals. Return the minimum number of intervals after merging. Example: [[1,3],[2,6],[8,10],[15,18]] → [[1,6],[8,10],[15,18]]
Given an array of intervals, merge all overlapping intervals. Return the minimum number of intervals after merging. Example: [[1,3],[2,6],[8,10],[15,18]] → [[1,6],[8,10],[15,18]]
Implement an LRU (Least Recently Used) cache with O(1) get and O(1) put. Explain why a naive HashMap alone doesn't solve this.
Implement an LRU (Least Recently Used) cache with O(1) get and O(1) put. Explain why a naive HashMap alone doesn't solve this.
You have a log file where each line has a timestamp and user ID. Find the K users who appear most frequently in the last N minutes. The file is 100GB and is being written to in real-time.
You have a log file where each line has a timestamp and user ID. Find the K users who appear most frequently in the last N minutes. The file is 100GB and is being written to in real-time.