Search an element in a Sorted & Rotated Array | Binary Search, Part 3 | DSA-One Course #24

  Рет қаралды 114,678

Anuj Bhaiya

Anuj Bhaiya

3 жыл бұрын

Hey guys, In this video we're going to solve an important problem on Binary search. It's called Search an element in a sorted and rotated array. This is a common question in many interviews. We'll learn how binary search can be modified to solve different kind of real-world problems
🥳 Join our Telegram Community:
Telegram channel: telegram.me/realanujbhaiya
Telegram group: telegram.me/dsa_one
🚀 Follow me on:
Instagram: / anuj.kumar.sharma
Linkedin: / sharma-kumar-anuj
Twitter: / realanujbhaiya
💸 Use coupon code ANUJBHAIYA on GeeksforGeeks to avail discounts on courses!
📚 Complete DSA Playlist: • DSA-One Course - The C...
Complete Android Development Playlist: • Android Development Tu...
Hashtags:
#anujbhaiya #dsaone
Ignore these tags:
search an element in a sorted and rotated array
binary search
search an element in sorted and rotated array
binary search in c
search an element in a nearly sorted array
search an element in a almost sorted array
search an element in a sorted and pivoted array
binary search program in c
binary search tree in data structure
search element in a circularly sorted array
search an element in matrix
single element in a sorted array
searching an element in array

Пікірлер: 198
@subirkumar6786
@subirkumar6786 Жыл бұрын
Consider this test case a[ ] = [ 3 , 1 ] and key =1 . The left part sorted condition must be if(a[low]
@LokendraSingh-wk7ix
@LokendraSingh-wk7ix 3 жыл бұрын
for correct output condition will be : ar[low]
@sangeethapinto
@sangeethapinto 2 жыл бұрын
I was stuck at this point. Thank you for pointing it out.
@sristy9823
@sristy9823 2 жыл бұрын
What about the input [1,0,1,1,1] key= 0
@LokendraSingh-wk7ix
@LokendraSingh-wk7ix 2 жыл бұрын
@@sangeethapinto welcome 🤗
@LokendraSingh-wk7ix
@LokendraSingh-wk7ix 2 жыл бұрын
@@sristy9823 array not defined in ascending or descending order...so it will be assumed ascending order.
@sristy9823
@sristy9823 2 жыл бұрын
@@LokendraSingh-wk7ix yes I think this code will work for this
@varadsalgare7848
@varadsalgare7848 3 жыл бұрын
I think I'll meet you in Amazon if i complete this course 📍❤️
@amanrai8010
@amanrai8010 2 жыл бұрын
I don't think so you can meet him now
@saurabhsaxena1992
@saurabhsaxena1992 2 жыл бұрын
I am going to amazon 😂🤣😹
@YusufKhan-ol4cd
@YusufKhan-ol4cd 2 жыл бұрын
👍
@deepakmahapatra047
@deepakmahapatra047 2 жыл бұрын
Did u met him on Amazon? 😁
@jayeshborse7901
@jayeshborse7901 Жыл бұрын
@@deepakmahapatra047 😂
@Anonymous-coder31
@Anonymous-coder31 3 жыл бұрын
Amazing explanation of this question 🔥🔥
@rupeshkarale3492
@rupeshkarale3492 2 жыл бұрын
I love your teaching technique thank you so much
@akhilesh59
@akhilesh59 3 жыл бұрын
Today only my friend was discussing about this question with me, and he explained me the approach, which I was not able to understand completely. And what a coincidence, you uploaded the same question video with an easy explanation! Thanks for the video.. Now I don't think that i will forget this question :)
@hashmatmohammed5807
@hashmatmohammed5807 2 жыл бұрын
how much did u complete java dsa
@Pratik_yadaw
@Pratik_yadaw 10 ай бұрын
where you work at bro?
@coldfish6187
@coldfish6187 7 ай бұрын
nice, you have friends who discuss dsa with you
@abdushaik7621
@abdushaik7621 3 жыл бұрын
superb bro ...plz do more and more on DSA asap ....white board keeps focus on the topic great
@debdhritiroy6868
@debdhritiroy6868 3 жыл бұрын
yeah, was badly stuck with this one for quite a while
@afsarali-hz5lt
@afsarali-hz5lt 3 жыл бұрын
I am also
@AshishKumar-pq6pr
@AshishKumar-pq6pr 3 жыл бұрын
Bhaiya aafat lecture tha.....katai jahar parhate ho aap 😅😅
@prabalbhadoria5398
@prabalbhadoria5398 2 жыл бұрын
Man what a teacher 💪🏻
@sagardas4218
@sagardas4218 2 жыл бұрын
Thanks Anuj Bhaiya
@ashvinimeshram5242
@ashvinimeshram5242 3 жыл бұрын
Thanks ,really great explaination👍👍
@JaiSagar7
@JaiSagar7 2 жыл бұрын
Awesome iterative sir 🔥🔥🔥🔥
@pranaypanda5146
@pranaypanda5146 8 ай бұрын
Great explanation. The sorted part was the main trick why we can't create a discrete if-else checks to check all case. Thanks
@kapilkumarsangwan7546
@kapilkumarsangwan7546 3 жыл бұрын
thanks a lot bhaiya for such a great explanation and please upload the videos fastly
@merajansari0773
@merajansari0773 2 жыл бұрын
avi tak ka sabse easy solution for this question wow anuj bhaiya
@pj2464
@pj2464 Жыл бұрын
this is the best explanation for this question with enough examples thank you bhaiya
@user-tq2tf8ei5t
@user-tq2tf8ei5t 4 ай бұрын
Sir, awesome explanation
@sawanpatel3491
@sawanpatel3491 2 жыл бұрын
thanks bhaiyya. Great explanation
@madhavdua8588
@madhavdua8588 2 жыл бұрын
great efforts bhaiya
@AYUSHKUMAR-xj4wc
@AYUSHKUMAR-xj4wc Жыл бұрын
Great Explanation!!!
@OmRatnaparkhe
@OmRatnaparkhe 6 ай бұрын
Thank you bhaiya
@Pr3kashSingh
@Pr3kashSingh 2 жыл бұрын
Thanks Sir ji.
@CarelessMni
@CarelessMni Жыл бұрын
thank you very much sir. Love from Bangladesh
@beinghappy9223
@beinghappy9223 2 жыл бұрын
Thank u so much bhaiya 💝
@siddhantyadav4531
@siddhantyadav4531 3 жыл бұрын
Good Job Sir 👍👍👍👍
@abhishekverma7874
@abhishekverma7874 Жыл бұрын
Facing issue but clear by this video thanx
@mohammedirfan5744
@mohammedirfan5744 8 ай бұрын
anuj bhaiya is the best
@chandnibhavsar437
@chandnibhavsar437 2 жыл бұрын
Probably the best thing i found on you tube today :) Great explanation... Gonna start seeing your content
@agyaani8060
@agyaani8060 3 жыл бұрын
Thaaanks a lot bhaiyaa❤
@lokendrasingh9780
@lokendrasingh9780 2 жыл бұрын
thank you bhaiya for this amazing video
@someshpundir788
@someshpundir788 Жыл бұрын
baut badiya
@yogeshdeshpande9532
@yogeshdeshpande9532 3 жыл бұрын
Thanks bhaiya 🤩
@prashantchakrawarti42
@prashantchakrawarti42 Жыл бұрын
thank you bhaiya 😊🙏
@levi-lb6dp
@levi-lb6dp 2 жыл бұрын
Kyaa baat hai 🔥🔥🔥
@joydeepsarkar4774
@joydeepsarkar4774 Жыл бұрын
in the right part sorted in the if condition it will be key
@ujjwalgorain7594
@ujjwalgorain7594 Ай бұрын
Thanks
@BECEG_Bodhit
@BECEG_Bodhit Жыл бұрын
i watched 2 videos and finally i found solution
@vishalsaxena2312
@vishalsaxena2312 Ай бұрын
In if condition, a[mid] should be checked as a[mid] >= a[low], else it will not pass few cases like in array arr a= [3,1] and target as 1. otherwise explanation was very clear and very helpful as well. Thanks
@JustU-cc5td
@JustU-cc5td 3 жыл бұрын
Thank you Anuj bhayi , let me explain I had started your java placement lecture on the "apni kaksha" channel 🙏 how can I explain within 3 days, I had completed till Loops I never thought you make that much easier concept of java, And I promise to you, I will complete a whole playlist, once again a big thank you, Your Subscribe Omkar.🙋‍♂️
@hashmatmohammed5807
@hashmatmohammed5807 2 жыл бұрын
how much did u complete ....?
@siddhantyadav4531
@siddhantyadav4531 3 жыл бұрын
This is one of the best playlist on You tube tube for DS Algo
@avinashdharme2234
@avinashdharme2234 3 жыл бұрын
*Exactly, explanation bohot sahi tarike se bataya hai is playlist me* *Thoda slow rate of video, but explanation me koi compromise ni hai*
@hashmatmohammed5807
@hashmatmohammed5807 2 жыл бұрын
how much did u complete java dsa
@aarindey
@aarindey 3 жыл бұрын
if(a[low]
@starkendeavours7072
@starkendeavours7072 3 жыл бұрын
Kaunsa case miss ho jayega? Thik hi toh hain sab! Line 5 mein toh wo case already satissfy ho rha hain. Equals to wala, greater than and less than... All are okay.
@aarindey
@aarindey 3 жыл бұрын
array =[5,3] Search 3 me... default return hoga
@lakhannagar91
@lakhannagar91 3 жыл бұрын
@@aarindey you are right dude.
@YU-lz8hd
@YU-lz8hd 3 жыл бұрын
@@AnujBhaiya It is wrong. In 2nd iteration low=0 and high=1 so it returns -1. if(a[low]
@AnujBhaiya
@AnujBhaiya 3 жыл бұрын
Correct!
@santrawebtech35
@santrawebtech35 2 жыл бұрын
you are awesome i started learning from your channel i find your channel is like amazon pay new ad event i had it but i dont know it
@codedByAyush
@codedByAyush Ай бұрын
Just WoW
@RonitSagar
@RonitSagar Жыл бұрын
Bhaiya aapne ek edge case choor diya hai jb array kaa size 2 ho [3,1] ,target =1; tb aapka code "IF " waale part me naa jaa k else waale me chara jayega ...or fir -1 return karega. so, if(a[low]
@prakharsaxena9189
@prakharsaxena9189 3 жыл бұрын
bhaiya videos thode fast upload kro..please
@aniket_devil
@aniket_devil 3 жыл бұрын
Bhaiya ek fee structure pae bhi vedio bna do for Bca and Mca courses for different College's🙏
@Abhishek-ql3qu
@Abhishek-ql3qu Жыл бұрын
Bhaiya second condition should be arr(low)
@hetshah4890
@hetshah4890 3 жыл бұрын
Bhaiya we are greatful for you..🙏 Thank you for this amazing series!!..👍
@CodesBros
@CodesBros 2 жыл бұрын
Correct Solution in Py3
@ashishjaswal1437
@ashishjaswal1437 2 жыл бұрын
Wow What a explanation of this question by a software engineer, that what's experience matters .Even Coding Ninjas and Geeks For Geeks failed to Explain this Problem.
@monkeeys23
@monkeeys23 3 жыл бұрын
I was hoping to see a video for non cs student to how to start and get into FAANG DO IT IF YOU CAN
@chahakarora4203
@chahakarora4203 3 жыл бұрын
Bhaiya, please make a video on how to get PPO during internship
@abirberacse9827
@abirberacse9827 2 жыл бұрын
Can we use modulus operator to modify the bs?
@sakets.saurav
@sakets.saurav 3 жыл бұрын
Bhaiya.....c++ me dsa pdhna chaiye ya koi aur language me ??
@anuragsingla4090
@anuragsingla4090 3 жыл бұрын
bhaiya total kitne videos honge is course ke
@mohdkaifkhan3302
@mohdkaifkhan3302 3 жыл бұрын
Please teach fast bhaiya DSA course
@khudkikhoz
@khudkikhoz 3 жыл бұрын
Another great video ❣💞
@princedubey597
@princedubey597 3 жыл бұрын
And you are very hardworking person
@mohdkaifkhan3302
@mohdkaifkhan3302 3 жыл бұрын
Bhaiya aap kha chale jte h vedio post nhi karte h
@dwivedi6037
@dwivedi6037 3 жыл бұрын
Thankyou bhiya ♥️♥️
@ashishkumarshawhitchem2017
@ashishkumarshawhitchem2017 2 жыл бұрын
int start=0; int end=nums.length-1; while(start=nums[start]){ if(target>=nums[start] && target
@aalirazaniazi8314
@aalirazaniazi8314 3 жыл бұрын
Anuj bhayya mere paas computer nahi he or me coddin sikhna chahta hun try krrha hun me mujhe ap raspberry pi 4 ke bare me batai kya vo kaam karega mujhe lena chahiye ya nhi
@comedyhub26
@comedyhub26 3 жыл бұрын
Bro iss playlist ko continue krdo..... Imp questions 😀
@aehsasmathur5950
@aehsasmathur5950 3 жыл бұрын
what if the pivot point is before the mid-term?
@pratiksonawane9944
@pratiksonawane9944 Жыл бұрын
There is one small mistake just replace left part side if condition a[low]
@prajjawalkumarpatel9360
@prajjawalkumarpatel9360 Жыл бұрын
definitely otherwise we loose some case like [1] or [3,1] where we find 1;
@himanshughodmare2922
@himanshughodmare2922 3 жыл бұрын
Always helpful ❤️🔥
@elucidate2348
@elucidate2348 3 жыл бұрын
vaiya we need full web development course , please vaiya
@shuaibansari5526
@shuaibansari5526 2 жыл бұрын
What is time complexity for this algorithm?
@AbhishekA-81
@AbhishekA-81 3 жыл бұрын
Solved the same question yesterday 😂😂 Thanks btw it will clear concepts.
@abhishekdubey9920
@abhishekdubey9920 Жыл бұрын
Far better then glamorous sharadha
@chandankeshari6600
@chandankeshari6600 3 жыл бұрын
bhaiya please isme jab duplicates honge toh wo wala case per video bna dijiye
@piyushgogoriya5673
@piyushgogoriya5673 3 жыл бұрын
@anuj bhaiya JAVA +DS +ALGO walli playlist ko complete kero na ...
@AbhishekAnand92
@AbhishekAnand92 Жыл бұрын
Great explanation sir....however it's not working for array: [3,1], need to add more boundary condition for low/high
@subirkumar6786
@subirkumar6786 Жыл бұрын
just replace left part side if condition a[low]
@nikhilsood6126
@nikhilsood6126 3 жыл бұрын
Bhaiya Ds is must... But what about dbms and operating system?
@aryanverma6921
@aryanverma6921 3 жыл бұрын
Ise toh kar le pehle
@ShivaniSharma-jm1is
@ShivaniSharma-jm1is Ай бұрын
this code is not working for some test case, for example, arr =[3,1] and is key is 1 , for left part sorted condition must be if(a[low]
@merajansari0773
@merajansari0773 2 жыл бұрын
bhaiya advance dsa v kuch soachye
@Mike-lf9zj
@Mike-lf9zj 3 жыл бұрын
Great stuff!! I think while checking if the left side is sorted, instead of a[low] < a[mid], we need to check a[low]
@AnshTyagi_1
@AnshTyagi_1 2 жыл бұрын
failed testcase of leetcode right??
@subirkumar6786
@subirkumar6786 Жыл бұрын
just replace left part side if condition a[low]
@lakshyasinghchouhan2850
@lakshyasinghchouhan2850 Жыл бұрын
it will not work for input = [3,1] target=1
@vikashkumar-rr6hb
@vikashkumar-rr6hb 3 жыл бұрын
thnks bhaiya
@amanmiglani6043
@amanmiglani6043 2 жыл бұрын
if we get an array something like this: 50,60,90,10,20,30,40 here mid ele: is 10 and now both side are sorted then can you please explain me in this how to move forward #newbie just got a doubt so asked in the comment @anuj
@harikiran2381
@harikiran2381 5 ай бұрын
if (a[low]
@rishavkumar1839
@rishavkumar1839 Жыл бұрын
I am getting an error when the array size is 2 and the last element is 1 For eg : array = [3,1] And if searching for key=1. am getting an error. Can someone please fix
@subirkumar6786
@subirkumar6786 Жыл бұрын
just replace left part side if condition a[low]
@tech_wizard9315
@tech_wizard9315 3 жыл бұрын
Please add questions list for each video of dsa series which would be enough for practice for tech giants
@Pratik_yadaw
@Pratik_yadaw 10 ай бұрын
which company you are in rn?
@vaibhavsharma6413
@vaibhavsharma6413 Жыл бұрын
not running on this test case [3,1] target=1
@HimanshuSharma-cm8hi
@HimanshuSharma-cm8hi 3 жыл бұрын
What will be time complexity logn or something different?
@adammechaeil9339
@adammechaeil9339 3 жыл бұрын
log(n)
@CodesBros
@CodesBros 2 жыл бұрын
class Solution: def search(self, nums: List[int], target: int) -> int: l = 0 r = len(nums)-1 while(l
@yashgupta-fk3zc
@yashgupta-fk3zc 3 жыл бұрын
bhaiya luv u💜❤️
@ridersniper4964
@ridersniper4964 Жыл бұрын
in urdu (thank you == jazakallah khair){ cout
@crazgys3609
@crazgys3609 3 жыл бұрын
Thanks bhai jee! Ek python ke upar detailed tutorial for begineers banao na plzz! jaise apne java ka banaya tha 1-2 ghante ka.plzz bhaiya.reply karna plzz.
@freecontent2438
@freecontent2438 2 жыл бұрын
Lal phool neela phool Anuj bhaiya buti-phool
@eshanchourasia287
@eshanchourasia287 3 жыл бұрын
Bhaiya if suppose the given array is 3 4 1 5 6 7 8 then when mid element will be 5 and if I compare for whether the left side is sort ,it will give postive result but if we see the array it's not sorted as it's 3 4 1 5? so here I m getting confused as how are we getting sure that left will be sorted if the condition that you showed is correct,pls do reply Bhaiya.
@rashidttahasildar5439
@rashidttahasildar5439 2 жыл бұрын
Bro if u see carefully there is " and " condition present so if both the cases are true only then u can say left part is sorted and by the way u need to have a key also to compare and say that left part is sorted
@anujkumarsharma1013
@anujkumarsharma1013 2 жыл бұрын
Your input is invalid. The given array should be sorted and then maybe rotated. Your input array doesn't satisfy the criteria.
@jahanviraycha7859
@jahanviraycha7859 2 жыл бұрын
code is not working for [15,17,1,5,7,9,11] because it should be a[low]
@ayoushpaul8156
@ayoushpaul8156 3 жыл бұрын
if i m interested in tech fields like software development, AI, ML. Is it necessary for me to study Digital logic and computer design, computer architecture and organization, operating system in BTech. i really feel bore of these subjects. Plzzz help 🙏🙏
@0070vishal
@0070vishal 2 жыл бұрын
If you want a good job learn DS and algo else you can learn AI and ML and work for small companies or either can be a PhD researcher
@vijayeeratna
@vijayeeratna 3 жыл бұрын
it is failing in one test case [3,1] key = 1 low =0 high=1 mid =0 low = 0 high = -1 result -1
@thapliyalsahab34
@thapliyalsahab34 3 жыл бұрын
when trees and graphs will come???????????????????????????
@muskanmaheshwari9412
@muskanmaheshwari9412 2 жыл бұрын
this code got a bit stuck for the case of [3,1] hence need to change a bit in, if case make it a[low]
@kasammomin9379
@kasammomin9379 Жыл бұрын
thanks
@InterceptOriginal
@InterceptOriginal 2 жыл бұрын
Can anyone run the program with [3,1] and key=1 input?
@aryanaswal2
@aryanaswal2 Жыл бұрын
class Solution { public int search(int[] nums, int target) { int index = -1; for(int i=0;i< nums.length;i++){ if(nums[i] == target){ index = i; break; } } return index; } }
@ritvik2634
@ritvik2634 3 жыл бұрын
if(a[low]
@pulkitchausali1354
@pulkitchausali1354 2 жыл бұрын
yes it should be if(a[low]
@hashmatmohammed5807
@hashmatmohammed5807 2 жыл бұрын
@@pulkitchausali1354 thanks dude.....i was struck
@sanchityadav6753
@sanchityadav6753 2 жыл бұрын
@@hashmatmohammed5807 or just simply write the condition if(nums[mid]>nums[end])
@jimcheriyan1801
@jimcheriyan1801 2 жыл бұрын
Thanks bro I was stuck figuring out this
BS-4. Search Element in Rotated Sorted Array - I
16:38
take U forward
Рет қаралды 223 М.
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 11 МЛН
Получилось у Миланы?😂
00:13
ХАБИБ
Рет қаралды 5 МЛН
Это реально работает?!
00:33
БРУНО
Рет қаралды 1,9 МЛН
MISS CIRCLE STUDENTS BULLY ME!
00:12
Andreas Eskander
Рет қаралды 20 МЛН
BS-6. Minimum in Rotated Sorted Array
17:08
take U forward
Рет қаралды 147 М.
7 Number of Times a Sorted array is Rotated
23:25
Aditya Verma
Рет қаралды 204 М.
Search in rotated sorted array | Leetcode #33
13:52
Techdose
Рет қаралды 83 М.
How I Failed the Google Coding Interview (and lessons I learned)
14:24
Search in Rotated Sorted Array  #Binary Search Rotations Leetcode 33.
21:09
5 Math Skills Every Programmer Needs
9:08
Sahil & Sarra
Рет қаралды 1 МЛН
LeetCode Problem: 153. Find Minimum in Rotated Sorted Array | Java Solution
13:56
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 11 МЛН