Skip to content

Instantly share code, notes, and snippets.

@meetkool
Created December 30, 2025 15:00
Show Gist options
  • Select an option

  • Save meetkool/a733180ef4a4517b937a0be42298ac02 to your computer and use it in GitHub Desktop.

Select an option

Save meetkool/a733180ef4a4517b937a0be42298ac02 to your computer and use it in GitHub Desktop.
[BLOG] Untitled Post
title location images tags privacy createdAt updatedAt
Untitled Post
19.2283, 72.9481
blog
quick-post
public
2025-12-30 14:59:59 UTC
2025-12-30 15:00:24 UTC

TWO SUM CORE CONCEPT │ ├── Mathematical Reality: A + B = Target => B = Target - A │ ├── Decision: How to find B? │ │ │ ├── I don't want extra memory? ──▶ Brute Force (O(n²)) │ │ │ ├── Is the array already sorted? ──▶ Two Pointers (O(n)) │ │ │ ├── Can I use memory to be super fast? ──▶ Hash Map (O(n)) │ │ │ │ │ └── Two-Pass: Put all in Map, then Search. │ │ └── One-Pass (BEST): Search in Map, then Put. │ │ │ └── Do I need the original index? │ ├── NO ──▶ Sort it and use Two Pointers. │ └── YES ──▶ Use Hash Map (Value -> Index mapping).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment