🎯 Top 20 Data Structures & Algorithms Questions

Master coding interviews with the most frequently asked DSA questions from top tech companies

1. Two Sum - Find two numbers that add up to a target

Easy

Given an array of integers and a target sum, return indices of two numbers that add up to the target. You may assume that each input has exactly one solution.

Python

2. Reverse a Linked List

Easy

Reverse a singly linked list iteratively and recursively. This is a fundamental linked list problem.

Python

3. Valid Parentheses - Check if brackets are balanced

Easy

Given a string containing just the characters '(', ')', ', ', '[' and ']', determine if the input string is valid. Brackets must close in the correct order.

Python

4. Maximum Subarray (Kadane's Algorithm)

Medium

Find the contiguous subarray within an array which has the largest sum. This is solved efficiently using Kadane's algorithm.

Python

5. Binary Tree Level Order Traversal (BFS)

Medium

Traverse a binary tree level by level from left to right using Breadth-First Search (BFS).

Python

6. Longest Substring Without Repeating Characters

Medium

Find the length of the longest substring without repeating characters using sliding window technique.

Python

7. Merge Intervals

Medium

Given a collection of intervals, merge all overlapping intervals.

Python

8. Lowest Common Ancestor of Binary Tree

Medium

Find the lowest common ancestor (LCA) of two nodes in a binary tree.

Python

9. Course Schedule (Topological Sort / Cycle Detection)

Medium

Determine if you can finish all courses given prerequisites. This is a graph cycle detection problem.

Python

10. LRU Cache Implementation

Hard

Design and implement a Least Recently Used (LRU) cache with O(1) time complexity for both get and put operations.

Python

11. Binary Search

Easy

Implement binary search to find the index of a target value in a sorted array.

Python

12. Climbing Stairs (Dynamic Programming)

Easy

You're climbing a staircase with n steps. Each time you can climb 1 or 2 steps. How many distinct ways can you climb to the top?

Python

13. Product of Array Except Self

Medium

Given an array, return an array where each element is the product of all elements except itself, without using division and in O(n) time.

Python

14. Kth Largest Element in Array (QuickSelect)

Medium

Find the kth largest element in an unsorted array using QuickSelect algorithm.

Python

15. Rotated Sorted Array Search

Medium

Search for a target in a rotated sorted array in O(log n) time.

Python

16. Word Break (Dynamic Programming)

Medium

Given a string s and a dictionary of words, determine if s can be segmented into space-separated sequence of dictionary words.

Python

17. Number of Islands (Graph DFS/BFS)

Medium

Count the number of islands in a 2D grid where '1' represents land and '0' represents water.

Python

18. Coin Change (Dynamic Programming)

Medium

Find the minimum number of coins needed to make up a given amount using unlimited coins of given denominations.

Python

19. Validate Binary Search Tree

Medium

Determine if a binary tree is a valid Binary Search Tree (BST).

Python

20. Trapping Rain Water

Hard

Given an elevation map where the width of each bar is 1, compute how much water can be trapped after raining.

Python

DSA Interview Tips