Algorithms
Interviews
Computer Science
Programming
Career
Ask anything about this article
Hi! I've read this article.
What would you like to know?
@farhan
After analyzing thousands of interview experiences from LeetCode, GeeksforGeeks, and Glassdoor, these are the 50 most commonly asked DSA problems, organized by pattern. Master these, and you'll be prepared for 90% of technical interviews.
Two pointers is the most frequently tested pattern. It's used when you need to find pairs or subarrays in sorted data.
pythondef two_sum(nums, target):
seen = {}
for i, num in enumerate(nums):
complement = target - num
if complement in seen:
return [seen[complement], i]
seen[num] = i
pythondef max_area(height):
left, right = 0, len(height) - 1
max_water = 0
while left < right:
width = right - left
h = min(height[left], height[right])
max_water = max(max_water, width * h)
if height[left] < height[right]:
left += 1
else:
right -= 1
return max_water
Used for problems involving contiguous subarrays or substrings.
pythondef length_of_longest_substring(s):
char_set = set()
left = 0
max_len = 0
for right in range(len(s)):
while s[right] in char_set:
char_set.remove(s[left])
left += 1
char_set.add(s[right])
max_len = max(max_len, right - left + 1)
return max_len
pythondef search(nums, target):
left, right = 0, len(nums) - 1
while left <= right:
mid = (left + right) // 2
if nums[mid] == target:
return mid
if nums[left] <= nums[mid]:
if nums[left] <= target < nums[mid]:
right = mid - 1
else:
left = mid + 1
else:
if nums[mid] < target <= nums[right]:
left = mid + 1
else:
right = mid - 1
return -1
pythondef max_depth(root):
if not root:
return 0
return 1 + max(max_depth(root.left), max_depth(root.right))
pythonfrom collections import deque
def level_order(root):
if not root:
return []
result = []
queue = deque([root])
while queue:
level = []
for _ in range(len(queue)):
node = queue.popleft()
level.append(node.val)
if node.left: queue.append(node.left)
if node.right: queue.append(node.right)
result.append(level)
return result
pythondef climb_stairs(n):
if n <= 2:
return n
a, b = 1, 2
for _ in range(3, n + 1):
a, b = b, a + b
return b
pythondef lcs(text1, text2):
dp = [[0] * (len(text2) + 1) for _ in range(len(text1) + 1)]
for i in range(1, len(text1) + 1):
for j in range(1, len(text2) + 1):
if text1[i-1] == text2[j-1]:
dp[i][j] = dp[i-1][j-1] + 1
else:
dp[i][j] = max(dp[i-1][j], dp[i][j-1])
return dp[-1][-1]
| Week | Topics | Problems |
|---|---|---|
| 1 | Arrays, Two Pointers | 10 problems |
| 2 | Sliding Window, Binary Search | 10 problems |
| 3 | Trees, Graphs, BFS/DFS | 10 problems |
| 4 | Dynamic Programming | 10 problems |
| 5 | Linked Lists, Stacks, Heaps | 10 problems |
Consistency beats intensity. Solve 3-4 problems daily for 5 weeks, and you'll be ready for any coding interview.