Two pointers is the cheapest optimisation in DSA, turns many O(n²) problems into O(n). Hindi explanations of the three flavours: opposite ends (Two Sum II, Container with Most Water), fast/slow (cycle detection, middle of list), same direction (remove duplicates).
Neeche is topic ka Hinglish explanation hai, wahi jo hamare course lesson mein audio narration ke saath chalta hai. Code English mein hai, samjhana Hindi mein.
Valid Palindrome dekhne mein easy lagta hai, aur hai bhi, par sirf tab jab tum sahi tool uthao. Galat tool memory kha jaata hai. Sahi tool hai do pointers andar ki taraf chalte hue, junk characters skip karte hue. Aaj hum yeh skip-pointer pattern lock karenge taaki uske upar bane bara harder problems mein bhi kaam aaye.
Pattern hai dono ends se two pointers, ek skip predicate ke saath. Jab bhi tum dekho "dono sides se compare karo" ya "andar ki taraf shrink karo kuch elements ignore karte hue": wahi hint hai. Trick hai bookkeeping clean rakhna. Har advance ko bound i less than j ka respect karna hai, warna tum end se bahar nikal jaate ho.
Unlock yeh hai ki comparison in place ho sakta hai. Ek pointer index zero pe rakho aur doosra last index pe. Agar koi bhi pointer non-alphanumeric character pe hai, andar slide karte raho jab tak alphanumeric na mile. Phir dono characters lowercase mein compare karo. Different hain to false return karo. Warna dono pointers ek-ek step andar karo aur repeat karo.
def is_palindrome(s):
i, j = 0, len(s) - 1
while i < j:
while i < j and not s[i].isalnum():
i += 1
while i < j and not s[j].isalnum():
j -= 1
if s[i].lower() != s[j].lower():
return False
i += 1
j -= 1
return True
Complexity: Filter then reverse: time O(n), space O(n); Two pointers (in place): time O(n), space O(1).
Welcome to Two Sum II. Yeh problem Two Sum jaisa hi hai, bas input mein ek extra word hai: sorted. Yeh ek word tumhe hash map drop karne deta hai aur O of n time mein O of one extra space ke saath solve karne deta hai. Aaj tum two-pointer convergence pattern seekhoge jo ek poori family of problems ko unlock karta hai.
Pehle pattern recognition. Jab bhi input ek sorted array ho aur question pair, triple, ya window poochhe jo sum ya difference condition satisfy kare: yeh two pointers ka cue hai. Sorted order hi iss ko kaam karne deta hai. Iske bina, kaunsa side shrink karna hai yeh reason nahi kar sakte.
Ab asli unlock. Ek pointer leftmost element pe rakho aur ek rightmost pe. Inka sum dekho. Agar sum chhota hai, badhaane ka ek hi tareeka hai: left ko aage badhao, kyunki right side ka har dusra element chhota ya equal hai. Agar sum bada hai, ghataane ka ek hi tareeka hai: right ko peechhe le aao. Equal ho gaya toh kaam khatam. Yeh two pointers hai, aur O of one space mein chalta hai.
def two_sum(numbers, target):
l, r = 0, len(numbers) - 1
while l < r:
s = numbers[l] + numbers[r]
if s == target:
return [l + 1, r + 1]
elif s < target:
l += 1
else:
r -= 1
return []
Complexity: Brute force (two nested loops): time O(n²), space O(1); Hash map (Two Sum solution, re-applied): time O(n), space O(n); Two pointers (sorted-array unlock): time O(n), space O(1).
Container With Most Water Blind 75 ka pehla problem hai jahan optimization data structure nahi: ek idea hai. Brute force n-squared toh koi bhi likh dega. Interviewer dekh raha hai ki tum words mein argue kar paate ho ya nahi ki optimal two-pointer walk kabhi answer miss kyun nahi karta. Yahi argument aaj hum build karenge.
Pattern hai two pointers jo dono ends se shrink karte hain, har step pe ek greedy choice ke saath. Yeh tumhe wahan dikhta hai jab answer do indices ka function hota hai, aur array ke dono ends maximum starting width dete hain. Sorted Two Sum, Three Sum, Trapping Rain Water, Valid Palindrome: same skeleton. Greedy rule har baar alag, lekin skeleton bilkul same.
Ab asli unlock: yeh non-obvious hai, dhyaan se suno. Ek pointer har end pe rakho, widest possible container. Area hota hai min of two heights times width. Improve karne ke liye, tumhe ek pointer inward move karna hi padega, jo hamesha width shrink karega. Toh area gain karne ka ek hi tareeka hai: height-cap upar jaaye. Shorter bar area ko cap karta hai. Agar tum shorter bar fix rakho aur taller wale ko inward move karo, cap same rahega ya gir jaayega, aur width shrink ho jaayegi: area sirf gir hi sakta hai. Toh ek hi safe, possibly-improving move hai: shorter bar ko abandon karo aur uska pointer inward step karo. Bas yahi pura proof hai.
def max_area(height):
l, r = 0, len(height) - 1
best = 0
while l < r:
h_left, h_right = height[l], height[r]
area = min(h_left, h_right) * (r - l)
if area > best:
best = area
if h_left <= h_right:
l += 1
else:
r -= 1
return best
Complexity: Brute force (all pairs): time O(n²), space O(1); Two pointers + greedy (one pass): time O(n), space O(1).
This free course is built for students who finished Blind 75 and want broader pattern coverage, and anyone targeting FAANG-level Indian tech interviews (Razorpay, Uber India, Google India, Microsoft IDC). If you have ever Googled two pointers pattern in hindi (hinglish) with problems and bounced off paid-subscription paywalls or content that assumes you already know everything, this is the course for you.
This page is part of our flagship free course, NeetCode 150. The full course is delivered as short, focused lessons, each with bilingual narration (English and Hinglish), interactive practice widgets, and a clear before-and-after so you can feel yourself getting better. You can pause for weeks and pick up exactly where you left off, your progress is saved.
One phone-number signup unlocks every course on Techwave Academy: AI Bootcamp, Python for Class 4 / 6 / 8 / 10 / CBSE 12, Git, Linux, Spoken English, IOI Prep, Foundation Bootcamp, Blind 75, NeetCode 150, Claude Mastery, Tableau, Power BI, SQL, and Excel. Yes, all 18, forever free.
Blind 75 first is the recommended path, it is shorter (4 weeks) and forces you to learn each pattern once. Then NeetCode 150 deepens coverage.
Yes, every lesson has a Hindi narration track.
Python, Java, and C++ side-by-side for each problem.
It runs your code against the same test cases LeetCode uses for these problems. You see Pass/Fail per case.
Yes, 100% free.
Click below to open NeetCode 150. You will land on the course dashboard, see the week-by-week plan, and can start Lesson 1 immediately. No trial period, no payment screen, no upgrade pop-ups, ever.