DSA & Patterns
12 min read•Oct 18, 2026

The 14 DSA Patterns You Actually Need for Placements

Why mastering core algorithmic patterns beats grinding 500 random problems on LeetCode.

SV

StudyVex Editorial Team

Engineering & Placement Mentors

#DSA#Placement Roadmap#Two Pointers#Sliding Window#Algorithms

1. The Random Problem Trap

Every year during placement season, college campuses see the same phenomenon: students grind 400 or 500 disconnected LeetCode problems, yet freeze when an interviewer asks a slight twist on an array problem.

Why does this happen?

Because solving problems by memorization fails the moment an interviewer modifies the constraints. Interviewers at Google, Amazon, Microsoft, and high-growth startups do not ask textbook questions; they assess your ability to identify structural invariants and apply an algorithmic archetype.

When you classify problems by their underlying pattern, a list of 500 problems shrinks down to just 14 core patterns.


2. Pattern 1: Two Pointers (Opposite & Same Direction)

The Two Pointers pattern utilizes two memory references to iterate across an array or sequence, typically moving toward each other or in lockstep.

When to apply:

  • The input array is sorted (or can be sorted without violating time constraints).
  • You are looking for pairs, triplets, or sub-ranges that meet a specific target sum.
  • In-place reversal or partitioning is required with $O(1)$ extra memory.

Classic Archetype: Pair with Target Sum

Given a sorted integer array nums and an integer target, find two indices such that their sum equals target.

cpp
1// C++20 Optimal Two Pointers Implementation
2#include <vector>
3#include <utility>
4
5std::pair<int, int> findTargetPair(const std::vector<int>& nums, int target) {
6 int left = 0;
7 int right = static_cast<int>(nums.size()) - 1;
8
9 while (left < right) {
10 int currentSum = nums[left] + nums[right];
11 if (currentSum == target) {
12 return {left, right}; // Zero-indexed pair found in O(N) time
13 } else if (currentSum < target) {
14 left++; // Need a larger sum, move left pointer rightward
15 } else {
16 right--; // Need a smaller sum, move right pointer leftward
17 }
18 }
19 return {-1, -1};
20}

Complexity: Time $O(N)$, Auxiliary Space $O(1)$.


3. Pattern 2: Fast & Dynamic Sliding Window

The Sliding Window pattern maintains a valid subsegment (a "window") across contiguous elements of an array or string. It expands the right edge until constraints are violated, then shrinks the left edge to restore validity.

High-Frequency Interview Problems:

  1. Longest Substring Without Repeating Characters
  2. Minimum Size Subarray Sum
  3. Maximum Consecutive Ones with At Most $K$ Flips

Binary search isn't just for arr[mid] == target. In technical interviews, over 70% of binary search problems operate on Search Spaces with Monotonic Invariants (e.g., Koko Eating Bananas, Capacity to Ship Packages Within D Days, Aggressive Cows).

The Invariant Principle:

Always maintain a clean invariant on your search boundaries [low, high]. At every iteration:

  • Compute mid = low + (high - low) / 2 to guard against integer overflow.
  • Check a feasibility function isValid(mid).
  • Shrink the interval deterministically.

5. The 14-Pattern Placement Matrix

#PatternKey Trigger WordsClassic Problem
1Two PointersSorted array, pair sum, palindromes3Sum, Container With Most Water
2Sliding WindowContiguous subarray, min/max length with conditionLongest Substring Without Repeating
3Fast & Slow PointersCycle detection, middle of sequenceLinked List Cycle, Happy Number
4Modified Binary SearchSorted rotated array, min capacity, monotonic rangeSearch in Rotated Sorted Array
5Prefix Sum / HashSubarray sum equals K, equilibrium pointSubarray Sum Equals K
6Monotonic StackNext greater element, histogram areasDaily Temperatures, Largest Rectangle
7Topological SortCourse prerequisites, build order, DAG dependenciesCourse Schedule I & II
8Breadth-First SearchShortest path in unweighted graphs, level-orderWord Ladder, Rotting Oranges
9Depth-First SearchConnected components, tree traversals, backtracksNumber of Islands, Word Search
10Subsets & PermutationsGenerate combinations, state choicesSubsets II, N-Queens
11Two HeapsRunning median, balancing highest/lowest halvesFind Median from Data Stream
12K-way MergeMerge sorted lists/arraysMerge K Sorted Lists
130/1 & Unbounded KnapsackSubset choices with capacity weightsCoin Change, Partition Equal Subset Sum
14Intervals & MergingOverlapping meetings, calendar schedulingMerge Intervals, Non-overlapping Intervals

6. Your 30-Day Pattern Action Plan

  1. Week 1 (Days 1–7): Master Two Pointers, Sliding Window, and Prefix Sums.
  2. Week 2 (Days 8–14): Fast & Slow Pointers, Monotonic Stack, and Modified Binary Search.
  3. Week 3 (Days 15–21): Trees, BFS/DFS Graphs, and Topological Sort.
  4. Week 4 (Days 22–30): Dynamic Programming (Knapsack & Subsequences) and Intervals.

Continue reading

Related Playbooks & Roadmaps

View all playbooks →
Technical Interview & Projects9 min read

How to Explain Your B.Tech Project in Technical Interviews

When an interviewer says 'Walk me through your resume project,' 80% of candidates describe features instead of architecture. Learn the exact 5-minute framework to showcase design decisions, scalability, and technical maturity.

3.5k•Oct 18, 2026
Read