14 Coding Patterns That Solve 90% of FAANG Interviews [2026 Guide]
If you have been grinding LeetCode and feel like every problem looks new, you are missing the meta-skill: most coding interview problems are variants of 14 patterns. Learn these 14 templates well and you reduce a 600-problem grind to a 60-problem grind, three to four representative problems per pattern.
This is not theory; it is the exact blueprint product companies' interviewers themselves use to pick problems. They open a pattern bucket, pick a question, and tweak it. Your job is to recognise which bucket they reached into.
Background: review the DSA sheet for placements 2026 for the foundational data-structure refresher.
How to Use This Guide
- Read the pattern's signature, what does the problem look like when this pattern applies?
- Memorise the template, there is one canonical loop or recursion shape per pattern.
- Solve the 3 sample problems listed for each pattern, then 5–10 variants from LeetCode tagged with the same pattern.
- Re-read this list every Sunday for 6 weeks. By week 4 you will be classifying problems faster than you can solve them.
Pattern 1, Sliding Window
Signature: asked to find a subarray, substring, or window with a property, longest, shortest, sum equals K, contains K distinct, etc.
Template:
def sliding_window(arr, k):
left = 0
state = init_state()
result = init_result()
for right in range(len(arr)):
update(state, arr[right])
while not valid(state):
shrink(state, arr[left])
left += 1
result = update_result(result, right - left + 1)
return result
Sample problems:
- Longest substring without repeating characters
- Maximum sum subarray of size K
- Smallest subarray with sum ≥ S
Pattern 2, Two Pointers
Signature: sorted array, asked to find pairs, triplets, or partition by some condition.
Template:
def two_pointers(arr, target):
left, right = 0, len(arr) - 1
while left < right:
s = arr[left] + arr[right]
if s == target:
return [left, right]
elif s < target:
left += 1
else:
right -= 1
Sample problems:
- Pair with sum K in sorted array
- Three-sum (find triplets summing to 0)
- Container with most water
Pattern 3, Fast and Slow Pointers (Floyd's)
Signature: linked list cycle, finding the middle, or detecting if a sequence eventually repeats.
Template:
def has_cycle(head):
slow = fast = head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow == fast:
return True
return False
Sample problems:
- Detect cycle in linked list
- Find the start of the cycle
- Happy number (does the sum-of-squared-digits loop hit 1?)
Pattern 4, Merge Intervals
Signature: intervals are given; you need to merge, schedule, find overlap, or count free time.
Template:
def merge_intervals(intervals):
intervals.sort(key=lambda x: x[0])
merged = [intervals[0]]
for current in intervals[1:]:
if current[0] <= merged[-1][1]:
merged[-1][1] = max(merged[-1][1], current[1])
else:
merged.append(current)
return merged
Sample problems:
- Merge overlapping intervals
- Insert a new interval into a sorted list
- Meeting rooms II (minimum rooms required)
Pattern 5, Cyclic Sort
Signature: array contains numbers in a known range like 1 to N, find the missing, the duplicate, or the smallest missing positive.
Template:
def cyclic_sort(nums):
i = 0
while i < len(nums):
j = nums[i] - 1
if 0 <= j < len(nums) and nums[i] != nums[j]:
nums[i], nums[j] = nums[j], nums[i]
else:
i += 1
return nums
Sample problems:
- Find the missing number from 0 to N
- Find all duplicates in an array
- Find first K missing positives
Pattern 6, In-place Linked List Reversal
Signature: reverse a list, or reverse parts of a list (every K nodes, alternate K).
Template:
def reverse_list(head):
prev = None
curr = head
while curr:
nxt = curr.next
curr.next = prev
prev = curr
curr = nxt
return prev
Sample problems:
- Reverse a linked list
- Reverse every K nodes
- Reverse alternating K nodes
Pattern 7, Tree BFS
Signature: any tree-traversal problem where you need level-by-level processing, level order, zigzag, right view.
Template:
from collections import deque
def tree_bfs(root):
if not root: return []
result = []
queue = deque([root])
while queue:
size = len(queue)
level = []
for _ in range(size):
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
Sample problems:
- Level order traversal
- Zigzag level order
- Right side view of a binary tree
Pattern 8, Tree DFS
Signature: path-related, root-to-leaf, sum equals target, all paths, max depth, diameter.
Template:
def dfs(node, target, path, result):
if not node: return
path.append(node.val)
if not node.left and not node.right and sum(path) == target:
result.append(list(path))
dfs(node.left, target, path, result)
dfs(node.right, target, path, result)
path.pop()
Sample problems:
- All root-to-leaf paths
- Path sum equals K
- Diameter of binary tree
Pattern 9, Two Heaps
Signature: find the median in a stream, or split data into two halves where one half holds the larger and one holds the smaller.
Template: maintain a max-heap of the lower half and a min-heap of the upper half, balanced so their sizes differ by at most 1.
Sample problems:
- Find median from a data stream
- Sliding window median
- Maximize capital with K projects
Pattern 10, Subsets / Backtracking
Signature: generate all combinations, permutations, partitions, or solve N-queens / Sudoku / word break.
Template:
def subsets(nums):
result = []
def backtrack(start, path):
result.append(list(path))
for i in range(start, len(nums)):
path.append(nums[i])
backtrack(i + 1, path)
path.pop()
backtrack(0, [])
return result
Sample problems:
- All subsets of a list
- All permutations
- Partition string into palindromes
Pattern 11, Modified Binary Search
Signature: sorted array but rotated, or asked to find boundary, or asked to search in infinite array.
Template:
def search_rotated(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
Sample problems:
- Search in rotated sorted array
- Find first / last position of target
- Find peak element
Pattern 12, Top K Elements
Signature: find the K largest, K smallest, K most frequent, or K closest.
Template:
import heapq
def top_k_frequent(nums, k):
freq = {}
for n in nums:
freq[n] = freq.get(n, 0) + 1
return [n for n, _ in heapq.nlargest(k, freq.items(), key=lambda x: x[1])]
Sample problems:
- K largest elements
- K most frequent words
- K closest points to origin
Pattern 13, K-way Merge
Signature: K sorted lists or arrays, merge them, find the smallest range, or find the kth element across all.
Template: push the head of each list into a min-heap; pop the smallest, push the next from that list.
Sample problems:
- Merge K sorted linked lists
- Smallest range covering elements from K lists
- Find Kth smallest element in M sorted lists
Pattern 14, 0/1 Knapsack and Topological Sort
0/1 Knapsack signature: maximise / minimise some value with a constraint, often with item-pick or item-skip choice.
Template:
def knapsack(weights, values, capacity):
n = len(weights)
dp = [[0] * (capacity + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
for w in range(capacity + 1):
if weights[i-1] <= w:
dp[i][w] = max(dp[i-1][w], dp[i-1][w - weights[i-1]] + values[i-1])
else:
dp[i][w] = dp[i-1][w]
return dp[n][capacity]
Topological Sort signature: dependencies between tasks, schedule courses, build order, alien dictionary.
Sample problems (knapsack):
- Equal subset sum partition
- Coin change (min coins)
- Longest common subsequence
Sample problems (topo sort):
- Course schedule (can finish?)
- Course schedule II (return order)
- Alien dictionary
Drilling Plan: 6 Weeks to Proficiency
| Week | Patterns | Goal |
|---|---|---|
| 1 | Sliding Window, Two Pointers, Fast & Slow | Solve 4 problems per pattern |
| 2 | Merge Intervals, Cyclic Sort, Reversal | Solve 4 problems per pattern |
| 3 | Tree BFS, Tree DFS | Solve 6 problems per pattern |
| 4 | Two Heaps, Subsets, Modified Binary Search | Solve 4 problems per pattern |
| 5 | Top K, K-way Merge, Knapsack | Solve 4 problems per pattern |
| 6 | Topological Sort + mixed mock | One problem from each pattern, 25-min timer |
By the end of week 6, you should be able to classify the pattern of any new problem within 60 seconds and start writing the template within 90 seconds. That is the unlock, the rest is execution speed.
For company-specific drills, see Infosys SP/DSE coding questions, TCS NQT mock test, and the system design basics for freshers once you finish DSA.
Explore this topic cluster
More resources in Topics & Practice
Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.
Paid contributor programme
Sat this this year? Share your story, earn ₹500.
First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story — with byline.
Submit your story →Ready to practice?
Take a free timed mock test
Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.
Start Free Mock Test →