Skip to content

Patterns Overview ​

Learning roadmap ​

alt text

Two Pointers ​

Data Structures: Array, String or Linked List

Mental Model:

  • Traverse from opposite end and exhaust both OR Traverse from start and exhaust both
  • Traverse while pointer is less than length of given array
  • Update ans or do logic
  • If condition is met then move left pointer, else right.

Questions pattern:

  • Palindrom check
  • Max area of container
  • Reverse array
  • 2 Sum/3 Sum

Sliding Window ​

Data Structures: Array, String or Linked List

Mental Model:

  • Shrinking Window, Variable size window, Fixed size window.
  • Use of frequency map/set
  • Expand window, update ans, check window condition.
  • If window broken, shrink window

Questions pattern:

  • find 'k' distincts
  • contiguous sub-array
  • min/max sum
  • repeating characters
  • unique elements
  • longest/shortest segments