Please comment understood and give us a like if you got everything :)
@sudhanshushekhar4222 Жыл бұрын
Understood
@venup2813 Жыл бұрын
Understood
@alishashaikh3859 Жыл бұрын
Understood Sir.Thank you so much for your efforts
@pardhi8959 Жыл бұрын
understood
@mohammedahtesham7972 Жыл бұрын
understood
@kumpatisupriya394711 ай бұрын
"Don't need any paid resources when there's aStriver's free DSA playlist and DSA sheet. I'm sooooo grateful to you, bro! 🙇♂🙇♀🙇 Thank you!"
@pranavmandke88299 ай бұрын
At first I had trouble with lower, upper bound. But when I saw like the first 5 mins of the video, I could code the entire thing in one go!! Thanks a lot for such a clear explaination!
@MrProgrammerJay Жыл бұрын
You make us Feel DSA. Thanks for Amazing Lectures.
@Nikhil-xx5bh9 ай бұрын
I have gone through many KZbin playlist and paid courses, but this playlist is one of the best I have ever seen.
@shubhamagarwal14343 ай бұрын
#Free Education For All.. # Bhishma Pitamah of DSA...You could have earned in lacs by putting it as paid couses on udamey or any other elaerning portals, but you decided to make it free...it requires a greate sacrifice and a feeling of giving back to community, there might be very few peope in world who does this...."विद्या का दान ही सर्वोत्तम दान होता है" Hats Off to you man, Salute from 10+ yrs exp guy from BLR, India.....
@siddharthkhandelwal93310 ай бұрын
The edge cases in finding upperbound are 1. The element>k may not exist in that case low==n , now if arr[low-1]==k then UB=low-1 else UB=-1 2. The element>k exist at index =index ,now if arr[index-1]==k UB=index-1 else then UB=-1
@AyushMishra-b8w7 ай бұрын
If lower bound does not exist there is no need to find upperbound
@_._escanor_._10 күн бұрын
man this guys teaching energy levels are in whole another level dude !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
@jayant-baid Жыл бұрын
I have seen your book allocation, aggression cows problems, and I understood everything. Excited to see and learn more such question from U in BS series
@abhay9994 Жыл бұрын
Thank you so much, Striver! Your DSA course has been incredibly helpful to me. I've learned a lot and it has greatly improved my understanding of data structures and algorithms. Thank you for your dedication and expertise in creating such a valuable resource. I'm truly grateful for all the knowledge and skills I've gained through your course!❣❣
@saksham_16129 ай бұрын
How do you watch like you try a problem first then see solutions or you directly see solutions and then try other problems of the same concept
@utkarshprakash7837 Жыл бұрын
Every topic of DSA learnt from you with such beautiful explanation. Thanks striver❤
@JalalMujawar5 ай бұрын
Thank you for great video, we can avoid repeating the same code in both methods for finding the firstIndex and last using a simple boolean. flag: public int[] searchRange(int[] nums, int target) { int[] ans = {-1,-1}; if(nums.length == 0){ return ans; } int startIndex = search(nums, target, true); int endIndex = search(nums, target, false); ans[0] = startIndex; ans[1] = endIndex; return ans; } int search(int[] nums, int target, boolean findFirstIndex){ int ans = -1; int start = 0; int end = nums.length; while(start = nums.length) return ans; if (target < nums[mid]) end = mid - 1; else if (target > nums[mid]) start = mid + 1; else { ans = mid; if (findFirstIndex) end = mid -1; else start = mid + 1; } } return ans; }
@Manishgupta200 Жыл бұрын
Solve the problem by using lower and upper bound approach was very tricky and smartly approach
@nikhilhaspe27345 ай бұрын
Hats Off brother. Because your explanation I was able to code the below code. NOTE: Here is the dependency between first & last occurence, I mean you have to know if there is first occ. then you will find the last otherwise not. But what if we need to find them seprately i.e first & last occ. independently so below is the code for the same in Java class Solution { // Get Lower Bound // Means smallest index such that, arr[index] >= target public int getFirstOcc(int[] arr, int target){ int lb=0, ub=arr.length-1, mid, firstOccIndex=arr.length; while(lb = target){ firstOccIndex = mid; ub = mid - 1; }else{ lb = mid + 1; } } if(firstOccIndex == arr.length || arr[firstOccIndex] != target) return -1; else return firstOccIndex; } // Get Upper Bound // Means smallest index such that, arr[index] > target public int getLastOcc(int[] arr, int target){ int lb=0, ub=arr.length-1, mid, lastOccIndex=arr.length; while(lb target){ ub = mid - 1; lastOccIndex = mid; }else{ lb = mid + 1; } } if(lastOccIndex == 0) return -1; if(lastOccIndex == arr.length && arr[lastOccIndex-1] != target) return -1; if(arr[lastOccIndex-1] != target) return -1; return lastOccIndex - 1; } public int[] searchRange(int[] nums, int target) { int[] res = new int[2]; res[0] = getFirstOcc(nums, target); res[1] = getLastOcc(nums, target); return res; } }
@PrianshYajnikАй бұрын
I found the second solution myself after the recursion series . Thank you striver
@BhaveshKumar-z1h Жыл бұрын
Thank you Striver for creating such helpful content.
@CodewithKing3603 ай бұрын
understood perfectly stdBinarySearch & using lowerBound&upperBounds
@chathuryachenchupalli6535 Жыл бұрын
Most useful video for beginners Totally satisfied and well understand
@rishabh1S Жыл бұрын
Understood! Please continue this placement series.
@anuragsingh8910 Жыл бұрын
0:00 Intro 0:28 Problem Statement (First and Last Occurrences in Array) Explanation 1:28 Brute force method 2:46 Brute force pseudocode 3:33 Time Complexity of Brute force method 3:43 Optimised Solution (using lower_bound() method) 6:23 Covering the corner cases 8:21 Optimised Solution Code 9:47 Time and Space Complexity Analysis 10:35 Simple Binary Search approach for the problem 18:19 Pseudocode of the Binary Search approach 22:07 Code of the Binary Search approach (in C++) 23:15 Moving on to next problem (Count occurrences in Array) 24:34 Outro
@raaviumasusmitha9375 ай бұрын
awww!....23:43 @striver your smile🤩
@rushidesai2836Ай бұрын
Optimal solution was pretty genius.
@akhiljainth79607 ай бұрын
Striver, you are just amazing 🔥🔥🙏🙏, how simply you just taught a topic is insane.
@manavsingh5919 Жыл бұрын
Thank You so much....Understood everything
@Shivi325904 ай бұрын
Don't need any paid resources when there's a Striver's free DSA playlist and DSA sheet. I'm sooooo grateful to you, bro! Thank you!"
@mohammedraiyaan-bt6iy8 ай бұрын
Awesome lecture sir ❤❤❤❤
@BhargaviKalla-hl4np7 ай бұрын
thank you bro, i have learned a lot from this video,once again thank you bro
@bhushanambhore837823 күн бұрын
Smoothest Explanation!
@ashishbm3565 Жыл бұрын
bhai kya bande ho yar tum!! just awesome teaching like a woowww!!!
@77-siddharthsattyam244 ай бұрын
class Solution { public: vector searchRange(vector& nums, int target) { vectorans(2,-1); int lo = 0; int hi = nums.size()-1; while(lo target) hi = mid-1; else lo = mid+1; } return ans; } };
@paraschinchalkar15994 ай бұрын
did not understand it in first go,but will try again to find the solutions and the logic by myself
@cinime Жыл бұрын
Understood! Super fantastic explanation as always, thank you so so much for your effort!!
@saswatrath46467 ай бұрын
Understood but it was unique in itself to know that some interviewers might also won't know about lower and upper bounds.
@asphasquad30169 ай бұрын
Striver is a magician which have a magic to make any topic like a cup of cake😊
@suryanshsingh5304Ай бұрын
Understood! Amazing series
@LearnerAbhi214 ай бұрын
Understood very well bhai . And your energetic way of teaching makes it more interesting, thanx bhai, i am new to your channel, already late, but iguess its fine, no point in making regret in mind, eventually i will get my destination if i work hard, consistently...!!!
@dipingrover19705 ай бұрын
normal binary search i was able to do it on my own thanks a lot . 😊
@MYMIND252 Жыл бұрын
form now i am love with DSA thanks to you boss gulabi dil gulabi dil
@PoojaGurumurtiTamragouri6 ай бұрын
Understood, Best tutorial !!
@arnabsarkar52456 ай бұрын
I solved the count occurrences wala question using lower bound and upper bound method, i hole it will be accepted in the interview :)
@AnjuGupta-sz1uk Жыл бұрын
understood! really well explained
@naliniprakash7738 Жыл бұрын
It's crystal clear striver, I think this approach had more repeat nature. what if, when we find our x with BS, and move left side linearly to first index, and move right linearly to get last index ?
@innocentgamer8670 Жыл бұрын
that's again 0(N) , means the time complexity will increase , because it will iterate through every point
@agni50516 ай бұрын
Understood! lekin striver bhai ek chiz bolungi, thoda sa so bhi liya kro.
@vishaljoshi7752 Жыл бұрын
One lowerBound function only - search key and key+1 (-1) int pos(const vector& arr,int n ,int key) { int l = 0; int h = n-1; int mid; int index = arr.size(); while(l= key) { index = mid; h = mid-1; } else l = mid+1; } return index; } pair firstAndLastPosition(vector& nums, int n, int k) { int fp=-1,lp=-1; fp = pos(nums,n,k); lp = pos(nums,n,k+1)-1; if(fp
@AluwalaSrujan0523 Жыл бұрын
good work bro
@mainakdasgupta71304 ай бұрын
ohhh yess !! i found the god
@kingbadshah45210 ай бұрын
thanks striver understood everything
@striverdaaadi11 ай бұрын
best playlist ever👌👌👌
@blurbmusic15073 ай бұрын
love the energy sir
@DevanshiKapla Жыл бұрын
UnderStoodddddd , Super Fantastic explanation thankyouuuuuuuu striver
@bhavuk233810 ай бұрын
the edge case is just that the lower bound should not be equal to upper bound for the first and last occurence problem. if lb==ub then ans={-1,-1} else {lb,ub-1}
@tanya835311 ай бұрын
Understood!! and again thanks for such a wonderful job!!
@fenilpatel62386 ай бұрын
count Occurence is done with map
@fenilpatel62386 ай бұрын
But here we talk about binary search then it done with binary search don't be distract
@tapans9275 Жыл бұрын
Why doesn't the upper bound have any conditions like the lower bound in the first and last occurrence of an element in an array?
@CodeNinjaByte Жыл бұрын
there are 2 cases: 1. if element present then lower bound present same element and uppper bound present element greater then that , in striver example lower bound is 8 and upper bound is 11 in case of x=8 2. but if its not present then upper bound and lower bound will point to the same element soo lower bound ki condition write kr de means voh he upper bound ki hogi
@your_name96 Жыл бұрын
while checking for lb , he automatically checks if the element is present or not for ub as well.
@KrishnaKumar-b4m9p5 күн бұрын
in one sentence. because suppose if there happens any sort of problem with upper bound then the the first occurence of the element will also be the last occurence of the element. so after checking the conditions for lower bound no need to check anything for upper bound.
@md.imrankhan6912 Жыл бұрын
Thank you mr legend
@RISHABH-VERMA Жыл бұрын
HATS OFF TO YOU SIR ❤, WHAT AN EXPLANATION
@venkat.sairam Жыл бұрын
🎯 Key Takeaways for quick navigation: 00:02 📺 The video is part of a playlist in a DSA course called "Strivers A to Z DSA." 00:30 🧐 The problem being discussed is about finding the first and last occurrence of a given number X in a sorted array. 01:35 🤔 The initial solution involves a linear iteration through the array, checking and updating the first and last occurrence indices. 03:35 ⏰ The time complexity of the initial solution is O(n), which is not optimal for sorted arrays. 04:18 🧠 The goal is to optimize the solution to have a time complexity better than O(n). 05:10 📈 The concept of "lower bound" and "upper bound" is introduced to optimize the solution. 08:24 💻 Pseudocode for using "lower bound" and "upper bound" to find first and last occurrences is presented. 09:56 ⚙️ The time complexity of this optimized solution is O(log n), a significant improvement. 10:24 🔍 Some interviewers may request a binary search solution without using "lower bound" and "upper bound." 16:13 🔄 Binary search for finding the first and last occurrences is demonstrated with different scenarios. 18:45 📝 Pseudocode for writing custom binary search functions to find first and last occurrences is provided. 22:36 ⚠️ Be careful about edge cases where the element X may not exist in the array, which could affect the last occurrence calculation. 24:13 🧩 To count occurrences of X in a sorted array with duplicates, you can use the formula: (last occurrence - first occurrence) + 1. 24:39 👍 The presenter encourages viewers to understand the logic behind low bound and upper bound implementations for future coding rounds. Made with HARPA AI
@depelterturbo Жыл бұрын
Amazing
@aakashsharma780 Жыл бұрын
Understood Striver bhaiya 🙌
@HarshChoudhary-vm6eh Жыл бұрын
Understood! Very well.... thanks bhaiya for such energetic with awesome explanation videos... :)
@k.satish3663 Жыл бұрын
Understood! Clean explanation
@KrishnaKumar-b4m9p5 күн бұрын
while finding the last occurence we are doing upper bound -- 1 . but suppose there do not exist any last occurence of an element. In that case what is gonna happen????
@Pooja-wb7gy7 ай бұрын
This is all good I do understand the logic properly even I know how it is working and everything but when ever I try to code this on my own , I end it up with errors, like I familiar with c++ but it becomes hard for me to code these types of problems pls guide me what should I do to write these codes on my own,
@pacifier82823 ай бұрын
Your basics is not clear that may be the reason , practice solving questions thats the only way
@visheshdadhich66365 ай бұрын
Very good video!
@jayantachakraborty60667 ай бұрын
it feels really nice. Sitting in the Striver's Hostel Room of college and studying from you dada..😃 take love...
@RagaviSathiyamoorthy Жыл бұрын
Thank you bhaii understood so clearly and this is the first time I'm solving a medium level problem in leetcode with a clear understanding.
@AnjaliChoudhary-r3f5 ай бұрын
Is there some confusion in lower bound and upper bound
@oyeesharme3 ай бұрын
thanks bhaiya
@abulkhayer81765 ай бұрын
Note : For the last problem(counting occurences), using unordered_map is the optimal approach.
@RaunitJaiswal-s9v2 ай бұрын
Done enough for today
@crazybro43837 ай бұрын
I have a doubt in the approach in which we use lower bound and upper bound- In edge case you have taken if lb==n || arr[lb] !=k.........but according to me it should be if ub==n. Becoz what if array is 1 2 3 4 5 and target is 5......lb will point to the element 5 but ub will point to the the place after 5 ie n........so ub==n will take care of that edge case also but lb==n will not
@NonameNoname-f2t9 ай бұрын
UNDERSTOOD WELL AND GOOD SIR!!!!!!!!!!!
@infernogamer52 Жыл бұрын
Understood Bhaiya!
@pragatii90545 ай бұрын
Thank you 😊so much
@khalasianiket8165 ай бұрын
understood❤
@SYCOA12CHAITANYAASOLE6 ай бұрын
Understood !! 😍😍
@abhaymandal4903 Жыл бұрын
Understood!! Able to silve
@anishsinha3272 Жыл бұрын
can we simply do it by floor and ceil indices?
@augustinradjou3909 Жыл бұрын
Understood baiya
@NAMAN-gr5lc Жыл бұрын
UNDERSTOODDDD!
@divakarmishra_3792 Жыл бұрын
understood!
@Lofisasddle5 ай бұрын
understood bhaiya
@AnmolGupta-oj4lm Жыл бұрын
Understood Very Well!
@abdussalam-48364 ай бұрын
Striver is the best we have.
@sayantanpoddar542810 ай бұрын
understood understood understood
@per.seus._ Жыл бұрын
UNDERSTOOD💔
@ankush82438 ай бұрын
Thank you very much! 🙌💯❣
@yikes3807 Жыл бұрын
Thankful 🥰 understood
@VikasVerma-oo7fx6 ай бұрын
Understood ❤
@CodeMode9313 Жыл бұрын
Understood habibi
@bkmeher90053 ай бұрын
outstanding bhai
@mominarashad31035 ай бұрын
Is the link to code studio inaccessible ? or it is only me
@NazeerBashaShaik7 ай бұрын
Understood, thank you.
@adityaverma8985 ай бұрын
UNDERSTOOD😊
@culeforever5408 Жыл бұрын
understood :)
@tech_wizard9315 Жыл бұрын
Have you uploaded entire DP series?? ( From zero to advance level)
@takeUforward Жыл бұрын
Yes! Kitne br ek chiz puchoge
@monstercoder3665 Жыл бұрын
@@takeUforward He asks to drag your attention
@AkanshaSahu-qp3kd Жыл бұрын
@takeUforward Why did you remove the GFG problem links from the sheet bro??
@VikasBagri-i5j Жыл бұрын
Understood it very well... :)
@deepakkumar13204 Жыл бұрын
Super explanation 😊
@himanshidafouty3476 ай бұрын
Understood
@itzmartin20 Жыл бұрын
UNDERSTOOD SIR!
@SubramanyanS-x3t8 ай бұрын
can someone please ecplain how does this work .how he found out the answer of last problem by lastcourrence-firstocuracne +1?