<aside>

This section is part of the 5-hour LeetCode DSA Patterns course by Mukul Raina

SLIDE 9: Section Intro, Arrays, Hashing, and Prefix Sums

Arrays are the most common data structure in coding interviews. Nearly every problem starts with an array or string as input. The difference between a brute force O(n²) solution and an optimal O(n) solution almost always comes down to one skill: knowing when to trade space for time by using a hash map or a prefix sum.

This section teaches you three foundational patterns that eliminate redundant work. Hash sets eliminate redundant searches. Hash maps eliminate redundant counting. Prefix sums eliminate redundant range calculations. Once you internalize these three tools, a large portion of "medium" array problems become straightforward.

What We'll Cover:

  1. Hash set for existence checks
  2. Hash map for frequency and counting
  3. Complement lookup pattern
  4. Grouping by normalized key
  5. Prefix sum for subarray and range queries
  6. Product prefix and suffix technique
  7. Decision framework: hashing vs sorting vs prefix sums

Where This Appears in Interviews:

Company Type How This Section Appears
FAANG / Big Tech Two Sum variants, subarray sum problems, and frequency counting appear in nearly every phone screen
Mid-size companies Array manipulation and hash map usage are the most common first-round questions
Startups Practical data processing questions that reduce to hash maps or prefix sums
Online assessments Timed problems where O(n) vs O(n²) determines pass/fail on large test cases

Core Idea for This Section: When repeated lookup is the bottleneck, use hashing. When repeated range calculation is the bottleneck, use prefix sums. Both patterns trade O(n) space to eliminate an entire nested loop.

<aside>

Mukul Raina | youtube.com/@mukulraina | slides.mukulraina.com | LinkedIn

</aside>

<aside>

Mukul Raina | youtube.com/@mukulraina | slides.mukulraina.com | LinkedIn

</aside>


SLIDE 10: Hash Set for Existence Checks