Binary search is more than "divide by 2". We teach the lower-bound and upper-bound templates that solve 90% of binary-search problems on LeetCode. Hindi explanations + 4 worked examples.
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.
Welcome to Binary Search: interview toolkit ka sabse zyada reuse hone wala algorithm. Problem khud bahut simple hai: sorted array mein target dhoondho. Yeh lesson load-bearing isliye hai kyunki jo template aaj likhoge wo dozens of harder problems mein dikhega. Closed-interval form ek baar muscle memory mein aa gaya, toh off-by-one bugs se hamesha ke liye chhutkara mil jaata hai.
Problem padho. Tumhe ek sorted integer array nums aur ek target value diya hai. Agar target exist karta hai, uska index return karo, warna minus one return karo. Array ascending order mein sorted hai, saare elements unique hain, aur tumhe O of log n time mein run karna hai. Yahi last constraint asli baat hai: linear search bahut slow ho jaata.
Pattern recognition yahan sabse important skill hai. Jab bhi sorted array dikhe, ya koi monotonic predicate jahan tum pooch sako "answer mere left mein hai ya right mein?": binary search apply hota hai. Sortedness obvious version hai. Chhupa hua version hai search-on-answer: jab valid answers ek monotonic range banate hain, tum answer space ko hi binary-search karte ho.
Brute force se shuru karo taaki speedup quantify kar sako. Linear scan: left se right walk karo, target mile toh index return karo. O of n time. n equals dus to the four ke liye, das hazaar checks: modern hardware pe theek hai. Lekin n equals dus to the nine ke liye, ek billion: kai seconds. Sortedness ek information hai; linear scan usse waste kar deta hai.
Ab asli unlock. Kyunki array sorted hai, middle element dekhne se tumhe powerful information milti hai. Agar middle target se bada hai, target left half mein hi hoga. Agar middle target se chhota hai, target right half mein hi hoga. Har check baaki bachi range ka aadha throw out kar deta hai. Aadha, phir aadha, phir aadha: yahi log n hai.
Yeh canonical template hai. Gyaarah lines. Do pointers l aur r closed interval mark karte hain jo abhi bhi target rakh sakta hai. While loop tab tak chalta hai jab tak l less than or equal to r hai: equal pe emphasis. Mid as l plus r minus l divided by two compute hota hai. Teen branches: equal toh return, less toh right jao, greater toh left jao. Loop exit kar gaya, minus one return karo.
Chaar edges interviewers ko pasand hain. Empty array, while loop kabhi enter nahi hona chahiye, seedha minus one return. Target har element se chhota: l right move karta rahega, eventually r ko cross karega, minus one return. Target index zero ya last index pe: boundary updates mein wo positions include hone chahiye. Single-element array: l equals r at start, while ka equality check hi tumhe bachata hai.
Complexity. Linear search O of n time, O of one space hai. Binary search O of log n time, O of one space hai. n equals dus to the nine ke liye: linear ek billion ops, binary lagbhag tees ops. Yeh tees million times speedup hai, bilkul extra memory ke bina. Isiliye binary search har jagah dikhta hai: trade-off essentially free hai.
India context. Plain Binary Search TCS NQT, Infosys SP, aur Wipro Elite mein aata hai: usually "sorted array mein x ka index dhoondho" ke form mein. Product companies jaise Flipkart, Amazon India, Microsoft India, Adobe, aur Razorpay vanilla binary search rarely poochte hain; wo variants poochte hain: rotated array, first or last occurrence, ya search-on-answer problems jaise Koko Eating Bananas. Template cold yaad hona hi un sab ko unlock karta hai.
def search(nums, target):
l, r = 0, len(nums) - 1
while l <= r:
mid = l + (r - l) // 2
if nums[mid] == target:
return mid
elif nums[mid] < target:
l = mid + 1
else:
r = mid - 1
return -1
Complexity: Linear scan (ignores sortedness): time O(n), space O(1); Binary search (closed-interval): time O(log n), space O(1).
This free course is built for BTech / BE / BSc / MCA students preparing for campus placements at Amazon, Microsoft, Google, Adobe, Flipkart, Razorpay and similar Indian product companies; also professionals targeting switch interviews. If you have ever Googled binary search leetcode in hindi (hinglish) with code 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, Blind 75 LeetCode. 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 was assembled by an experienced interviewer specifically to cover every pattern that appears in SDE interviews, no duplicates, no fluff. It is the most efficient list for placement prep.
Both. Each lesson has a Hindi narration track for the explanation and English-only code with comments.
Every solution is provided in all three. Use the one your placement allows. If unsure, start with Python (cleanest), switch to C++ if you target high-frequency-trading or systems roles.
4-6 weeks if you do 2 problems a day with the in-browser editor and re-do tough ones.
Yes, 100% free, like every Techwave course.
Click below to open Blind 75 LeetCode. 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.