Core Interview Expectations

Interviewers evaluate

  • Pattern recognition
  • Time/space tradeoff awareness
  • Edge-case handling
  • Clean, readable logic

Universal Problem-Solving Steps

  • Clarify
  • Input size?
  • Sorted or unsorted?
  • Mutability allowed?
  • Brute Force First
  • State naive solution
  • Time complexity
  • Optimize
  • Use data structures
  • Recognize patterns
  • Implement
  • Clean variable naming
  • Guard clauses
  • Test
  • Empty input
  • Single element
  • Extremes

TIME & SPACE COMPLEXITY MASTER SHEET

Common Time Complexities

PatternComplexity
Single loopO(n)
Nested loopsO(n²)
Divide & ConquerO(n log n)
HashingO(1) avg
Binary SearchO(log n)
Sliding WindowO(n)
Two PointersO(n)

Python-Specific Costs

  • list append → O(1) amortized
  • list insert(0) → O(n)
  • dict lookup → O(1) avg
  • heap push/pop → O(log n)
  • set membership → O(1)

Common Algorithmic Patterns

Pattern 1: Frequency Counting

  • Anagrams
  • Duplicates
  • Majority element
from collections import Counter
freq = Counter(nums)

Pattern 2: Prefix Sums

  • Subarray sum
  • Range queries
prefix = [0]
for x in nums:
    prefix.append(prefix[-1] + x)

Pattern 3: Kadane’s Algorithm (Max Subarray)

    cur = best = nums[0]
    for x in nums[1:]:
        cur = max(x, cur + x)
        best = max(best, cur)

    TWO POINTERS PATTERN

    When to Use

    • Sorted arrays
    • Pairs / triplets
    • Palindromes

    Basic Template

      l, r = 0, len(arr) - 1
      while l < r:
          if condition:
              l += 1
          else:
              r -= 1

      Common Problems

      • Two Sum (sorted)
      • Container With Most Water
      • Remove duplicates

      SLIDING WINDOW PATTERN

      Fixed Window

        window_sum = sum(arr[:k])
        for i in range(k, len(arr)):
            window_sum += arr[i] - arr[i-k]

        Variable Window

          l = 0
          for r in range(len(arr)):
              while invalid_window:
                  l += 1

          Used For

          • Longest substring
          • Minimum window substring
          • Subarray sums

          HASHING & SET LOGIC

          Why Hashing Works

          • Converts lookup to O(1)
          • Trades memory for speed

          Classic Template

            seen = set()
            for x in arr:
                if x in seen:
                    return True
                seen.add(x)

            Common Uses

            • Two Sum
            • Cycle detection
            • Duplicate detection

            STACK PATTERNS

            Monotonic Stack

            • Used for:
            • Next Greater Element
            • Histogram area
            • Daily Temperatures

            Template (Increasing Stack)

              stack = []
              for i in range(len(nums)):
                  while stack and nums[stack[-1]] > nums[i]:
                      stack.pop()
                  stack.append(i)

              Valid Parentheses

                stack = []
                mapping = {')':'(', ']':'[', '}':'{'}

                QUEUE & DEQUE PATTERNS

                Overview

                Queue and deque patterns are commonly used for breadth-first search, sliding window problems, and efficient insertion and removal from both ends.

                BFS Queue Template

                  from collections import deque
                  q = deque([start])
                  while q:
                      node = q.popleft()

                  Sliding Window Max (Deque)

                    dq = deque()

                    Used in

                    • Level order traversal
                    • Shortest path
                    • Window maximum

                    QUEUE & DEQUE PATTERNS

                    Overview

                    Queue and deque patterns are fundamental for breadth-first search and sliding window problems, enabling efficient FIFO operations and constant-time insertions and deletions at both ends.

                    BFS Queue Template

                      from collections import deque
                      q = deque([start])
                      while q:
                          node = q.popleft()

                      Sliding Window Max (Deque)

                        dq = deque()

                        Used in

                        • Level order traversal
                        • Shortest path
                        • Window maximum

                        LINKED LIST PATTERNS

                        Overview

                        Linked list patterns such as fast and slow pointers and in-place reversal are commonly used to detect cycles, find middle nodes, and manipulate list structure efficiently.

                        Fast & Slow Pointers

                          slow = fast = head
                          while fast and fast.next:
                              slow = slow.next
                              fast = fast.next.next

                          Used for

                          • Cycle detection
                          • Middle node

                          Reverse Linked List

                            prev = None
                            cur = head
                            while cur:
                                nxt = cur.next
                                cur.next = prev
                                prev = cur
                                cur = nxt

                            BINARY SEARCH PATTERNS

                            Overview

                            Binary search patterns are used to efficiently search sorted data or monotonic search spaces by repeatedly dividing the problem in half.

                            Standard Binary Search

                              l, r = 0, len(arr)-1
                              while l <= r:
                                  mid = (l+r)//2

                              Lower Bound Pattern

                                while l < r:
                                    mid = (l+r)//2
                                    if arr[mid] < target:
                                        l = mid + 1
                                    else:
                                        r = mid

                                Used in

                                • Rotated arrays
                                • First/last position
                                • Search space problems

                                RECURSION & BACKTRACKING

                                Overview

                                Recursion and backtracking patterns explore solution spaces by making choices and undoing them, commonly used for combinatorial problems.

                                General Backtracking Template

                                  def backtrack(path):
                                      if condition:
                                          result.append(path[:])
                                          return
                                      for choice in choices:
                                          path.append(choice)
                                          backtrack(path)
                                          path.pop()

                                  Used for

                                  • Permutations
                                  • Combinations
                                  • Sudoku
                                  • N-Queens

                                  TREES: DFS & BFS

                                  Overview

                                  Tree traversal patterns such as DFS and BFS are used to explore nodes recursively or level by level.

                                  DFS (Recursive)

                                    def dfs(node):
                                        if not node:
                                            return
                                        dfs(node.left)
                                        dfs(node.right)

                                    BFS (Level Order)

                                      from collections import deque

                                      Common Problems

                                      • Diameter
                                      • Path sum
                                      • LCA

                                      HEAPS & PRIORITY QUEUES

                                      Overview

                                      Heaps and priority queues efficiently retrieve minimum or maximum elements and are widely used in optimization problems.

                                      Min Heap

                                        import heapq
                                        heapq.heappush(heap, x)
                                        heapq.heappop(heap)

                                        Max Heap Trick

                                          heapq.heappush(heap, -x)

                                          Used in

                                          • Top K
                                          • Median stream
                                          • Scheduling

                                          GRAPH PATTERNS

                                          Overview

                                          Graph traversal patterns explore nodes and edges using DFS or BFS to solve connectivity and path problems.

                                          DFS Graph

                                            def dfs(node):
                                                for nei in graph[node]:
                                                    if nei not in visited:
                                                        dfs(nei)

                                            BFS Shortest Path

                                              queue = deque([(start, 0)])

                                              Key Concepts

                                              • Adjacency list
                                              • Visited set
                                              • Directed vs undirected

                                              DYNAMIC PROGRAMMING (DP)

                                              Overview

                                              Dynamic programming breaks problems into overlapping subproblems and stores results to avoid recomputation.

                                              DP Thought Process

                                              • Define state
                                              • Transition
                                              • Base case
                                              • Answer extraction

                                              1D DP

                                                dp = [0]*(n+1)

                                                2D DP

                                                  dp = [[0]*m for _ in range(n)]

                                                  Common DP Problems

                                                  • Knapsack
                                                  • LIS
                                                  • Coin change
                                                  • Grid paths

                                                  FINAL INTERVIEW CHECKLIST

                                                  Overview

                                                  A concise checklist to ensure structured thinking, clean implementation, and correctness during technical interviews.

                                                  Reference: Cracking the Coding Interview (Gayle Laakmann McDowell), LeetCode Interview Guide

                                                  Before Coding

                                                  • Identify pattern
                                                  • State complexity

                                                  While Coding

                                                  • Clean loops
                                                  • No magic numbers

                                                  After Coding

                                                  • Edge cases
                                                  • Dry run example

                                                  TIME & SPACE COMPLEXITY MASTER SHEET

                                                  Overview

                                                  Common algorithmic patterns and their typical time complexities, frequently expected in interviews.

                                                  Reference: Introduction to Algorithms (CLRS), GeeksforGeeks Time Complexity Guide

                                                  Common Time Complexities

                                                  PatternComplexity
                                                  Single loopO(n)
                                                  Nested loopsO(n²)
                                                  Divide & ConquerO(n log n)
                                                  HashingO(1) avg
                                                  Binary SearchO(log n)
                                                  Sliding WindowO(n)
                                                  Two PointersO(n)

                                                  ARRAYS / STRINGS

                                                  Overview

                                                  Core array and string problems that form the foundation of most coding interviews.

                                                  Reference: LeetCode Patterns – Arrays & Strings

                                                  Patterns

                                                  ProblemPattern
                                                  Two Sum (unsorted)Hash MapStore complement
                                                  Two Sum (sorted)Two PointersMove inward
                                                  Maximum SubarrayKadaneCarry or restart
                                                  Product Except SelfPrefix/SuffixNo division
                                                  Best Time to Buy/SellGreedyTrack min
                                                  Subarray Sum = KPrefix Sum + HashCumulative counts
                                                  Longest ConsecutiveHash SetO(n) lookup
                                                  Anagram CheckFrequency CountCharacter counts

                                                  SLIDING WINDOW

                                                  Overview

                                                  Sliding window techniques optimize subarray and substring problems by maintaining a dynamic range.

                                                  Reference: NeetCode Sliding Window Patterns

                                                  Problems

                                                  ProblemPattern
                                                  Longest Substring Without RepeatVariableSet / freq map
                                                  Longest Repeating CharacterVariableMax freq
                                                  Minimum Window SubstringVariableFormed vs required
                                                  Max Sum Subarray (size k)FixedRolling sum

                                                  TWO POINTERS

                                                  Overview

                                                  Two pointer techniques reduce time complexity by exploiting sorted data or symmetric traversal.

                                                  Reference: LeetCode Two Pointer Guide

                                                  Problems

                                                  ProblemPattern
                                                  Container With Most WaterMove smaller
                                                  Remove DuplicatesSlow/Fast
                                                  3SumSort + inward
                                                  Palindrome CheckEnds inward

                                                  STACK

                                                  Overview

                                                  Stack-based patterns are used for matching, monotonic sequences, and range queries.

                                                  Reference: Monotonic Stack – GeeksforGeeks

                                                  Problems

                                                  ProblemPattern
                                                  Valid ParenthesesMatching
                                                  Daily TemperaturesMonotonic decreasing
                                                  Next Greater ElementMonotonic
                                                  Largest Rectangle HistogramMonotonic

                                                  LINKED LIST

                                                  Overview

                                                  Linked list problems focus on pointer manipulation and in-place transformations.

                                                  Reference: LeetCode Linked List Patterns

                                                  Problems

                                                  ProblemPattern
                                                  Detect CycleFast & Slow
                                                  Reverse ListIterative pointer swap
                                                  Merge Two ListsDummy node
                                                  Reorder ListSplit + reverse

                                                  BINARY SEARCH

                                                  Overview

                                                  Binary search applies to sorted data and monotonic answer spaces.

                                                  Reference: Binary Search Patterns – LeetCode

                                                  Problems

                                                  ProblemPattern
                                                  Sorted Array SearchIndices
                                                  Rotated ArrayModified mid
                                                  First/Last PositionLower/Upper bound
                                                  Koko Eating BananasAnswer space

                                                  TREES

                                                  Overview

                                                  Tree problems test recursion, traversal strategies, and hierarchical reasoning.

                                                  Reference: Tree Traversal Patterns – NeetCode

                                                  Problems

                                                  ProblemPattern
                                                  Max DepthDFS
                                                  Level OrderBFS
                                                  DiameterPostorder
                                                  LCADFS recursion
                                                  Path SumDFS

                                                  GRAPH

                                                  Overview

                                                  Graph problems emphasize traversal, connectivity, and dependency resolution.

                                                  Reference: Graph Algorithms – CLRS

                                                  Problems

                                                  ProblemPattern
                                                  Number of IslandsDFS/BFS
                                                  Clone GraphDFS + map
                                                  Course ScheduleTopological sort
                                                  Shortest PathBFS

                                                  DYNAMIC PROGRAMMING

                                                  Overview

                                                  Dynamic programming evaluates optimal solutions using overlapping subproblems.

                                                  Reference: Dynamic Programming – LeetCode & CLRS

                                                  Problems

                                                  ProblemPattern
                                                  Climbing Stairs1D DP
                                                  House Robber1D DP
                                                  Coin ChangeUnbounded knapsack
                                                  LISDP / Binary search
                                                  Unique PathsGrid DP

                                                  ARRAYS / STRINGS

                                                  Overview

                                                  Array and string problems form the core foundation of coding interviews and emphasize efficient traversal, hashing, and prefix techniques.

                                                  Reference: LeetCode Arrays & Strings Patterns, NeetCode Foundations

                                                  Problem Patterns

                                                  Problem TypePatternKey Insight
                                                  Two Sum (unsorted)Hash MapStore complement
                                                  Two Sum (sorted)Two PointersMove inward
                                                  Maximum SubarrayKadaneCarry or restart
                                                  Product Except SelfPrefix/SuffixNo division
                                                  Best Time to Buy/SellGreedyTrack min
                                                  Subarray Sum = KPrefix Sum + HashCumulative counts
                                                  Longest ConsecutiveHash SetO(n) lookup
                                                  Anagram CheckFrequency CountCharacter counts

                                                  SLIDING WINDOW

                                                  Overview

                                                  Sliding window techniques optimize contiguous subarray or substring problems by maintaining a dynamic range.

                                                  Reference: Sliding Window Patterns – NeetCode, LeetCode

                                                  Problems

                                                  Problem TypeWindow TypKey Variable
                                                  Longest Substring Without RepeatVariableSet / freq map
                                                  Longest Repeating CharacterVariableMax freq
                                                  Minimum Window SubstringVariableFormed vs required
                                                  Max Sum Subarray (size k)FixedRolling sum

                                                  TWO POINTERS

                                                  Overview

                                                  Two pointer techniques reduce complexity by scanning from multiple directions simultaneously.

                                                  Reference: Two Pointer Technique – GeeksforGeeks

                                                  Problems

                                                  ProblemPointer Movement
                                                  Container With Most WaterMove smaller
                                                  Remove DuplicatesSlow/Fast
                                                  3SumSort + inward
                                                  Palindrome CheckEnds inward

                                                  STACK

                                                  Overview

                                                  Stack-based patterns are used for matching problems and monotonic ordering.

                                                  Reference: Monotonic Stack Patterns – LeetCode

                                                  Problems

                                                  Problem TypeStack Type
                                                  Valid ParenthesesMatching
                                                  Daily TemperaturesMonotonic decreasing
                                                  Next Greater ElementMonotonic
                                                  Largest Rectangle HistogramMonotonic

                                                  LINKED LIST

                                                  Overview

                                                  Linked list problems focus on pointer manipulation and in-place transformations.

                                                  Reference: Linked List Patterns – LeetCode

                                                  Problems

                                                  ProblemPattern
                                                  Detect CycleFast & Slow
                                                  Reverse ListIterative pointer swap
                                                  Merge Two ListsDummy node
                                                  Reorder ListSplit + reverse

                                                  BINARY SEARCH

                                                  Overview

                                                  Binary search applies to sorted data and monotonic answer spaces.

                                                  Reference: Binary Search Patterns – LeetCode, CLRS

                                                  Problems

                                                  ProblemSearch Space
                                                  Sorted Array SearchIndices
                                                  Rotated ArrayModified mid
                                                  First/Last PositionLower/Upper bound
                                                  Koko Eating BananasAnswer space

                                                  TREES

                                                  Overview

                                                  Tree problems emphasize recursion, traversal strategies, and hierarchical reasoning.

                                                  Reference: Tree Traversal Patterns – NeetCode

                                                  Problems

                                                  ProblemTraversal
                                                  Max DepthDFS
                                                  Level OrderBFS
                                                  DiameterPostorder
                                                  LCADFS recursion
                                                  Path SumDFS

                                                  GRAPH

                                                  Overview

                                                  Graph problems test traversal, connectivity, and dependency management.

                                                  Reference: Graph Algorithms – CLRS, LeetCode

                                                  Problems

                                                  ProblemPattern
                                                  Number of IslandsDFS/BFS
                                                  Clone GraphDFS + map
                                                  Course ScheduleTopological sort
                                                  Shortest PathBFS

                                                  DYNAMIC PROGRAMMING

                                                  Overview

                                                  Dynamic programming solves optimization problems using overlapping subproblems and state transitions.

                                                  Reference: Dynamic Programming – CLRS, LeetCode

                                                  Problems

                                                  ProblemDP Type
                                                  Climbing Stairs1D DP
                                                  House Robber1D DP
                                                  Coin ChangeUnbounded knapsack
                                                  LISDP / Binary search
                                                  Unique PathsGrid DP

                                                  COMPANY-WISE PATTERN PRIORITY

                                                  Overview

                                                  Company-specific pattern focus based on real interview trends.

                                                  Reference: Interview Experiences – LeetCode, Glassdoor

                                                  Company Focus

                                                  Company NameDSA QuestionsHints
                                                  GoogleGraphs, Trees, Binary Search on Answer, DPComplex constraints, edge cases
                                                  Meta (Facebook)Sliding Window, Hashing, Two PointersSpeed, clarity, communication
                                                  AmazonTrees, Arrays, Sliding Window, BFSClean code, scalability
                                                  MicrosoftDP, Recursion, Graphs, StringsCorrectness, explanation
                                                  AppleArrays, Strings, Two PointersElegant solutions
                                                  Netflix / AirbnbGraphs, DFS, Design + DSADeep reasoning, tradeoffs