Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStats

Categories

πŸ€– Artificial Intelligence
☁️ Cloud and Infrastructure
πŸ’Ύ Data and Databases
πŸ’Ό Professional Skills
🎯 Programming and Development
πŸ”’ Security and Networking
πŸ“š Specialized Topics
HomeAboutTopicsPricingMy VaultStats
LEVEL 0
0/5 XP
GitHub
Β© 2026 CheatGridβ„’. All rights reserved.
Privacy PolicyTerms of UseAboutContact

Coding Interview Patterns Cheat Sheet

Coding Interview Patterns Cheat Sheet

Back to Mathematics and Algorithms
Updated 2026-05-21
Next Topic: Coding Theory and Error-Correcting Codes Cheat Sheet

Coding interview patterns are reusable algorithmic blueprints that map large families of problems to a small set of well-understood techniques. Mastering these patterns matters because interviewers at top companies deliberately recycle the same underlying structures β€” recognizing the pattern instantly is the difference between a clean O(n) solution and a frustrated brute-force attempt. The key insight is that pattern recognition, not memorization, is the skill being tested: the same two-pointer template that solves "pair sum in sorted array" also solves "container with most water" and "3Sum". Each pattern below includes the canonical template, the signal that tells you to apply it, and the complexity you should expect to quote.

What This Cheat Sheet Covers

This topic spans 15 focused tables and 96 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.

Table 1: Two PointersTable 2: Sliding WindowTable 3: Fast / Slow Pointers (Floyd's Cycle Detection)Table 4: Prefix Sum and Difference ArrayTable 5: Monotonic Stack and QueueTable 6: Binary Search and VariantsTable 7: BFS and DFS TemplatesTable 8: Heap Patterns (Top K and Two-Heap)Table 9: Linked List In-Place TechniquesTable 10: Backtracking (Subsets, Combinations, Permutations)Table 11: Tree Traversals and PatternsTable 12: Topological SortTable 13: Union-Find (Disjoint Set Union)Table 14: Dynamic Programming PatternsTable 15: Graph Algorithms and Advanced Patterns

Table 1: Two Pointers

Two pointers place one pointer at each end of a sorted (or partitioned) array and move them toward each other based on a condition, eliminating brute-force O(nΒ²) pair enumeration. A second variant uses both pointers moving in the same direction for partitioning or fast/slow detection β€” that variant is covered separately in Table 3.

TechniqueExampleDescription
Opposite-direction two pointers
l, r = 0, len(arr)-1
while l < r:
if arr[l]+arr[r]==target: return [l,r]
elif arr[l]+arr[r]<target: l+=1
else: r-=1
β€’ Works on sorted arrays
β€’ shrink the window from both ends based on whether the sum is too small or too large
Three-sum reduction
nums.sort()
for i in range(len(nums)-2):
l, r = i+1, len(nums)-1
# two-pointer inner loop
β€’ Fix one element, then run opposite-direction two pointers on the remainder
β€’ reduces O(nΒ³) β†’ O(nΒ²).
Partition / remove duplicates
slow = 0
for fast in range(1, len(nums)):
if nums[fast] != nums[slow]:
slow += 1
nums[slow] = nums[fast]
β€’ slow marks the boundary of the valid prefix
β€’ fast scans ahead β€” classic same-direction two pointers for in-place array compaction

More in Mathematics and Algorithms

  • Calculus Cheat Sheet
  • Coding Theory and Error-Correcting Codes Cheat Sheet
  • Abstract Algebra Essentials Cheat Sheet
  • Convex Optimization Cheat Sheet
  • Hash Tables and Hash Maps Cheat Sheet
  • Number Theory Cheat Sheet
View all 57 topics in Mathematics and Algorithms