How to use this page: These 25 problems are the most commonly asked easy-level DSA questions in coding interviews. They are ranked by frequency across Google, Amazon, Meta, Microsoft, and other top tech companies.

For each problem you will find the pattern it belongs to, which companies commonly ask it, a brief approach, a key insight, and the expected time/space complexity. Use the filter buttons to focus on a specific pattern.

1
Two Sum
LeetCode #1
Easy Hash Map
Google Amazon Meta Microsoft Apple

Iterate through the array. For each number, compute the complement (target - num) and check if it already exists in a hash map. If it does, return both indices. Otherwise, store the current number and its index in the map.

Key insight: A hash map turns the inner loop of a brute-force O(n^2) search into an O(1) lookup.
Time: O(n) Space: O(n)
2
Valid Parentheses
LeetCode #20
Easy Stack
Amazon Google Meta Bloomberg

Use a stack. Push opening brackets onto the stack. When you encounter a closing bracket, check if the top of the stack is the matching opening bracket. If not, or if the stack is empty, return False. At the end, the stack must be empty.

Key insight: A stack naturally handles nested matching because the most recent opening bracket must close first (LIFO).
Time: O(n) Space: O(n)
3
Merge Two Sorted Lists
LeetCode #21
Easy Linked List
Amazon Microsoft Google Apple

Create a dummy head node. Use two pointers to walk through both lists, always appending the smaller node to the merged list. When one list is exhausted, attach the remainder of the other list.

Key insight: The dummy head eliminates edge-case handling for the first node and simplifies the merge logic.
Time: O(n + m) Space: O(1)
4
Best Time to Buy and Sell Stock
LeetCode #121
Easy Greedy / DP
Amazon Meta Google Goldman Sachs

Track the minimum price seen so far as you iterate. At each step, compute the profit if you sold today (current price minus minimum). Update the maximum profit accordingly. One pass is all you need.

Key insight: You only need to track the running minimum and the maximum difference — no need to compare every pair.
Time: O(n) Space: O(1)
5
Valid Palindrome
LeetCode #125
Easy Two Pointers
Meta Microsoft Amazon

Use two pointers starting from both ends. Skip non-alphanumeric characters. Compare the characters at both pointers (case-insensitive). If they ever differ, return False. If the pointers meet, return True.

Key insight: Two pointers from opposite ends lets you verify symmetry in O(n) time without creating a cleaned copy of the string.
Time: O(n) Space: O(1)
6
Invert Binary Tree
LeetCode #226
Easy Tree / DFS
Google Amazon Meta

Recursively swap the left and right children of every node. Base case: if the node is None, return None. Swap left and right, then recurse on both subtrees. Return the root.

Key insight: Every subtree needs the same operation (swap children), making this a natural fit for recursion with a trivial base case.
Time: O(n) Space: O(h) where h is tree height
7
Valid Anagram
LeetCode #242
Easy Hash Map
Amazon Google Microsoft

Count the frequency of each character in both strings using a hash map (or Counter). If the frequency maps are identical, the strings are anagrams. Alternatively, use a single counter: increment for string s, decrement for string t, then check all counts are zero.

Key insight: Anagrams share the exact same character frequencies — comparing sorted strings works but is O(n log n), while frequency counting is O(n).
Time: O(n) Space: O(1) (fixed 26-char alphabet)
8
Binary Search
LeetCode #704
Easy Binary Search
Microsoft Amazon Apple

Maintain two pointers, left and right, defining the search range. Compute mid. If nums[mid] equals target, return mid. If target is smaller, move right to mid - 1. If larger, move left to mid + 1. Repeat until left exceeds right.

Key insight: Each comparison eliminates half the search space, giving logarithmic time on sorted input.
Time: O(log n) Space: O(1)
9
Linked List Cycle
LeetCode #141
Easy Linked List / Two Pointers
Amazon Microsoft Goldman Sachs

Use Floyd's Tortoise and Hare algorithm. Move a slow pointer one step and a fast pointer two steps at a time. If they meet, there is a cycle. If the fast pointer reaches the end (None), there is no cycle.

Key insight: In a cycle, the fast pointer gains one step per iteration on the slow pointer, so they must eventually collide.
Time: O(n) Space: O(1)
10
Maximum Subarray
LeetCode #53
Easy Dynamic Prog. / Kadane's
Amazon Google Microsoft LinkedIn

Use Kadane's algorithm. Maintain a running sum of the current subarray. If the running sum drops below zero, reset it to zero (start a new subarray). Track the maximum sum seen at any point.

Key insight: A negative running sum can never help a future subarray — it is always better to start fresh.
Time: O(n) Space: O(1)
11
Reverse Linked List
LeetCode #206
Easy Linked List
Amazon Microsoft Apple Bloomberg

Iterate through the list with three pointers: prev, curr, and next. At each step, save curr.next, point curr.next to prev, then advance prev and curr forward. When curr is None, prev is the new head.

Key insight: You reverse in-place by redirecting each node's next pointer to the previous node — no extra data structure needed.
Time: O(n) Space: O(1)
12
Contains Duplicate
LeetCode #217
Easy Hash Map / Set
Amazon Google Apple

Add each element to a set as you iterate. Before adding, check if it already exists in the set. If it does, return True immediately. If you finish the loop without a match, return False.

Key insight: A set provides O(1) membership testing, turning a brute-force O(n^2) comparison into a single-pass O(n) check.
Time: O(n) Space: O(n)
13
Maximum Depth of Binary Tree
LeetCode #104
Easy Tree / DFS
Amazon Google Microsoft

Recursively compute the depth of the left and right subtrees. The depth of the current node is 1 + max(left_depth, right_depth). Base case: if the node is None, return 0.

Key insight: The depth of any node depends only on the depth of its children — a textbook recursive subproblem.
Time: O(n) Space: O(h) where h is tree height
14
Climbing Stairs
LeetCode #70
Easy Dynamic Programming
Amazon Google Apple Adobe

The number of ways to reach step n equals the sum of ways to reach step n-1 and step n-2 (since you can take 1 or 2 steps). This is the Fibonacci sequence. Use two variables to iterate bottom-up in O(1) space.

Key insight: This is a Fibonacci problem in disguise — recognizing the recurrence relation is the entire challenge.
Time: O(n) Space: O(1)
15
Same Tree
LeetCode #100
Easy Tree / DFS
Amazon Google Bloomberg

Recursively compare both trees. If both nodes are None, return True. If one is None and the other is not, or their values differ, return False. Otherwise, recursively check left subtrees and right subtrees.

Key insight: Two trees are the same if their roots match AND their left subtrees match AND their right subtrees match — pure structural recursion.
Time: O(n) Space: O(h) where h is tree height
16
Symmetric Tree
LeetCode #101
Easy Tree / DFS
Amazon Microsoft Bloomberg

Write a helper that takes two nodes and checks if they are mirror images. Two nodes are mirrors if both are None, or both have the same value AND left1 mirrors right2 AND right1 mirrors left2. Call this helper with root.left and root.right.

Key insight: Symmetry means the left subtree is a mirror of the right subtree — compare outer children with outer children, inner with inner.
Time: O(n) Space: O(h) where h is tree height
17
Single Number
LeetCode #136
Easy Bit Manipulation
Amazon Google Apple

XOR all elements together. Since a XOR a = 0 and a XOR 0 = a, all duplicate pairs cancel out, leaving only the single unique number.

Key insight: XOR is both commutative and self-inverse — every pair cancels regardless of order, leaving only the unique element.
Time: O(n) Space: O(1)
18
Intersection of Two Linked Lists
LeetCode #160
Easy Linked List / Two Pointers
Amazon Microsoft Bloomberg

Use two pointers, one for each list. When a pointer reaches the end of its list, redirect it to the head of the other list. Both pointers will travel the same total distance and meet at the intersection node (or both reach None if no intersection).

Key insight: By switching lists at the end, both pointers traverse length_A + length_B steps, equalizing the offset difference.
Time: O(n + m) Space: O(1)
19
Move Zeroes
LeetCode #283
Easy Two Pointers
Meta Amazon Apple

Use a slow pointer to track the position where the next non-zero element should go. Iterate with a fast pointer. When you find a non-zero, swap it with the element at the slow pointer and advance slow. All zeroes bubble to the end.

Key insight: The slow pointer partitions the array into "processed non-zeroes" on the left and "everything else" on the right.
Time: O(n) Space: O(1)
20
Missing Number
LeetCode #268
Easy Math / Bit Manipulation
Amazon Microsoft Apple

Compute the expected sum of numbers 0 through n using the formula n*(n+1)/2. Subtract the actual sum of the array. The difference is the missing number. Alternatively, XOR all indices and all values — the missing number remains.

Key insight: The Gauss summation formula gives you the expected total in O(1), making the subtraction approach both elegant and efficient.
Time: O(n) Space: O(1)
21
Palindrome Linked List
LeetCode #234
Easy Linked List / Two Pointers
Amazon Meta Bloomberg

Find the middle of the list using slow/fast pointers. Reverse the second half in-place. Compare the first half with the reversed second half node by node. If all values match, it is a palindrome.

Key insight: Combining "find middle" and "reverse list" — two fundamental linked list operations — solves this in O(1) space.
Time: O(n) Space: O(1)
22
Min Stack
LeetCode #155
Easy Stack / Design
Amazon Google Microsoft Bloomberg

Maintain two stacks: one for the values and one for the running minimum. On push, also push the new minimum (min of current value and current top of min stack). On pop, pop from both stacks. getMin peeks the min stack.

Key insight: Storing the minimum at each stack level lets you retrieve it in O(1) even after pops, because each level remembers its own minimum.
Time: O(1) per operation Space: O(n)
23
Diameter of Binary Tree
LeetCode #543
Easy Tree / DFS
Meta Amazon Google

Use a recursive depth function. At each node, the diameter through that node is left_depth + right_depth. Track the global maximum diameter as you recurse. Return the depth (1 + max of children) for use by parent calls.

Key insight: The longest path may not pass through the root — you must check the diameter at every node and keep a running maximum.
Time: O(n) Space: O(h) where h is tree height
24
Subtree of Another Tree
LeetCode #572
Easy Tree / DFS
Amazon Meta Google

For each node in the main tree, check if the subtree rooted there is identical to the target tree (using the Same Tree check). If any node matches, return True. Recurse on left and right children.

Key insight: This combines tree traversal with the Same Tree subroutine — recognizing it as a composition of two simpler problems is the key.
Time: O(n * m) Space: O(h) where h is tree height
25
Squares of a Sorted Array
LeetCode #977
Easy Two Pointers / Sorting
Meta Amazon Google

Use two pointers at both ends of the array. Compare absolute values: the larger absolute value's square goes at the end of the result array. Move that pointer inward. Fill the result array from right to left.

Key insight: The largest squares come from the extremes (most negative or most positive), so two pointers from the edges fill the result in one pass.
Time: O(n) Space: O(n)
Africa & India's Best AI Academy
🤖 AI-first 🎓 Placement Assistance

You know the problems.
Now master the patterns.

Join the Best AI Programs — three 5-month courses, fully online, with placement assistance. Week 1 is free.

Explore our AI-era courses →