Foundations
Common Interview Patterns
Master essential foundational patterns: Two-Pass Strategy, In-Place Swapping, and Prefix State Accumulation.
Last Updated: August 2, 2026
•
20 min read
1. Introduction
What are FOUNDATIONS Interview Patterns?
FOUNDATIONS Interview Patterns represent the high-yield structural techniques used in technical interviews to solve linear, matrix, or non-linear computational problems efficiently.Why study them?
Instead of memorizing individual LeetCode solutions, mastering these core patterns allows you to instantly recognize problem invariants and apply verifiedO(N) or O(N log N) templates.
Where is it Used?
2. Mental Model
Imagine solving a complex puzzle where each piece has a predictable shape:
3. Core Patterns & Implementations
1. Two-Pass Strategy (Product Except Self)
Compute global metrics (like prefix products from left, then suffix products from right) in two independent linear passes without division.2. In-Place Swapping & Pointer Traversal
Swap elements in-place using left and right pointers to reverse arrays or partition items in O(N) time with O(1) auxiliary space.3. Prefix State Accumulation
Accumulate running state (sums, minimums, maximums) while iterating through a single pass to answer range and boundary queries.4. Visual Trace
5. Real-World Applications
6. Interview Perspective
How Interviewers Ask This Topic
Interviewers verify whether you recognize key problem constraints and select optimal patterns rather than defaulting to brute force.Common Mistakes
Warning: 1. Using division in Product of Array Except Self : Using division in Product of Array Except Self — fails when array contains zeros (0).
> 2. Allocating temporary arrays for simple string reversals, violating O(1) space constraints.: Allocating temporary arrays for simple string reversals, violating O(1) space constraints.