Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 05 · DSA · Clinic: arrays, hashing and stacks · about 14 min to read

Play it as a journeyTutor comes with a plan

Clinic #05: Two Sum

Pattern: Hashing (memory of the past) · LC 1

Two Sum
Two Sum · Open board

Ek hi sawaal ke teen jawab dikhaata hai: seedha tareeka, sort karke milna, aur yaad rakh kar dhoondna. Upar ka “LC 1” matlab LeetCode ka problem number 1.

Before you start. List mein har number ki apni jagah hoti hai, use uska index kehte hain, 0 se ginkar. Foundations #04: Hashing (O(1) "yaad") ya Hashing ne hash map ke andar (buckets, collisions) pehle dikhaya ho toh wahi machine yahan istemaal ho rahi hai, is note mein sirf ek problem pe.

Lesson 39 of 96 in DSA

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 1953: Luhn ka IBM memo, machine ko yaad-daasht dena
  • Ek list, ek target, aur bhool jaane ka dard
  • “Maine ye pehle dekha tha”, jab bhoolna band hua
  • Poochho pehle, yaad rakho baad mein
  • Sol 1 - brute force · O(n²) / O(1)
  • Sol 2 - sort + two pointer · O(n log n) / O(1)*
  • Sol 3 - hash map, one pass · O(n) / O(n) · BEST ✅
  • Naapa hua, teeno, n = 10² se 10⁵
  • Edge cases, chala ke, teeno pe
  • Trace: Sol 3, nums=[3,2,4], target 6
  • Do bug jo sample pass karte hain
  • Interview mein pehli baar, raasta
  • The Tell
  • Retrieval

Terms it explains: LC 1, index, O(n²), peeche, hash map, O(n), pehle, kagaar, badi aur negative, sorted nahi, bataana zaroori, BEST, invariant, hash map, one pass, BEST for unsorted, worst case, aakhri do, 27 ms, chalao, HAAN, index 1, [1,2], tab, pehle example pe sahi, chaaron, isi, Clarify, Brute force pehle bolo, Bottleneck pe ungli, One pass bolo, Order ka dhyaan, Edge + complexity, Hash map (O(1) recall), dobara scan, O(n)/O(n), Contains Duplicate, Group Anagrams.

Review DSA