CodeCamp Day 2 | Exploring Arrays and Problem Solving
Key Takeaways
Explores arrays and problem-solving challenges using Data Structures and Algorithms fundamentals
Full Transcript
foreign [Music] are you sure this course is just for 2499 yes and you know this is the only course with this expertise across the world no way yes way [Music] don't delay enroll now Jake's learning together hi everyone very good evening and welcome back to Geeks for geeks practice uh sorry welcome back to geek so Geeks and Welcome to our 21 days coding boot camp so guys please give me a plus one in the chat if my voice is clearly audible to everyone and everything is working fine then I'll introduce myself so my name is Yash divedi uh I'm a candidate Master on portforces five star on code shift and I'm currently working as a DSA Mentor at geek so Geeks for the past two years so guys uh please give me a plus one if everyone is excited and Ready for today's session and make sure to uh hit the like button as well so that we can get started with today's session and we can start solving the problems as well okay so hi Khushi hi Ankit uh hi Sai right so high power one hi everyone okay so let me share my screen and then I think that we can start uh discussing the problems okay so I'll quickly share my screen with all of you all right so I hope that my screen is getting shared properly correct guys uh I hope it is getting shared will you uh will you all uh yeah we will try to cover all the DSA Concepts Praveen Gupta we'll try to cover all the DSA Concepts okay uh all right so now let me do one thing let me quickly open the very first problem okay so as you can see if you have not enrolled again I'm reminding you if you are someone who has not enrolled so you can go to the very first link that is read this article link and the then you can enroll in this boot camp right so that you can get proper notifications and email for it now without further Ado let me get started with the problem solving okay you can give me a plus one if you can see my screen and make sure to hit the like button guys uh now I will just quickly share my screen so that we can move forward with the very first problem okay so all the three problems that are there they are still various companies so sort and ra right uh first problem is sort and and I'll quickly open this particular problem up uh on the two weeks platform right so this is the very first problem that we'll be discussing are all of you ready guys sort an array of zeros ones and twos everyone is ready can we start shall we start now okay guys all right so first of all let us quickly read this problem and understand what the problem actually says so the very first problem as I as we can see this problem that we are going to discuss the name of this problem is nothing but sort okay and array right you have to sort an array of zeros once and twos okay so basically what will happen is in this problem you will be given elements uh sir Siddharth sir will not take our session uh for today of Sana he is not going to take the session so I'll be taking your session for today okay uh right uh so this problem has been previously asked in paytm okay this problem has been asked in Flipkart it has been asked in Morgan Stanley Amazon Microsoft it has been asked in Oyo Samsung Snapdeal hike make my trip Ola Walmart a lot of companies have asked it Adobe also so basically what will be given is will be given an array of zeros ones and twos so we will be given a particular random array okay we'll be given an array in which what will happen in in any order the elements of that will be present will be only zeros ones and twos so suppose these kind of elements are going to be present here so what we need to do is we need to sort the array in such a way that at the front of the array zeros are present okay then in between ones are pressure and after that and after that for the remaining places two are present okay so is this part clear please write yes is the question clear to everyone this question problem statement is clear when I say that we have to sort an array of zeros ones and twos so we'll be given a normal array in which uh elements will be given elements that will be given will either be 0 will either be one or they will either be two and what we need to do here is we need to sort this array of zeros once and two so we need to sort the arena ascending order so basically whatever zeros we are having first of all we can have the zeros then we can have the ones and then we have we can have the twos okay uh location uh I think he might take the session but I cannot confirm about that okay so yeah uh like what how can we do this particular problem so in the very first approach or you can say in the very first Brute Force approach that can come to my mind is what like in the method one if I have to think so since I have to sort the arena so what I can use is I can do is I can use the sort function okay I can so use the sort in inbuilt function and like uh in whichever language I am using so I can use the salt salt in inbuilt function that is there in every language I can use the inbuilt sort function that is there and then what I can do is my array will get sorted okay so like in in C plus plus I can use uh normal sort AR dot begin comma ARR Dot N something like this right ARR Dot N so I can sort the array like that okay other if I'm using Java then I can use arrays.sort right similarly in uh address dot sort ARR in that I can do it like this right so we basically whatever language I am using in that language start from the very physic basic brother uh yes I'm starting from the very basic like basically sorting an array of zeros once and two so I'm starting it from the very basic itself but basically what you will do is first of all if you are having this array and you have to sort the zeros once and two side okay so if you sort if you want to so uh arrange the zeros first and then the ones and then the twos so I can use the inbuilt sort function okay and that that takes how much time n log n time I can use the inbuilt sort function and it will take the N log n time to sort the whole array is that clear guys please tell me is this is this part clear or not the tying complexity will be order of n log n if I use the inbuilt sort function and it will help me to get the array sorted okay so basically it will sort the sending order so all the zeros will come at the front then all the ones that are there they will come and then all the tools will come right and then the space complexity of the approach will be order of one correct is that clear if I have to bring all the zeros at the front then I have to bring all the ones and then I have to bring to bring all the twos can you go somewhat slope yes I will try to be a bit slow uh is this thing clear to everyone guys please tell me basically what we will do here is if you want if you have been given an array which consists of zeros ones and twos right and you have to bring the zeros at the front then once and then the then all the elements that are two so what you will what you can do is basically you can sort this array okay so the moment you sort this array then what by using the inbuilt sort function then zeros will come at the front then after that once and then after that too so basically sorting the array in ascending order you can say right we are sorting the array in ascending order that is what we can do here is that clip yeah yeah that is that is correct yeah if you are having the normal Arrow then you can do this uh correct shall we need so if this much part is clear please uh guys hit the like button okay please hit the like button if this uh this particular basic approach is clear then please hit the like button and give me a quick plus one as well in the chat if this is clear to everyone so I want a plus one from everybody right please include examples in Java so yeah I have said no like you will use RS dot sort if you are using Java uh okay the space complexity will be order of one because we are not going to take any extra space now we are not going to declare any extra array or we are not going to declare any extra data structure that is why the space complexity of the method one will be order of one is that clear to everyone guys please hit the like button and give me a plus one in the chat and then I will proceed further as well to the second method that we can have it okay bro calm down you are speaking very fast all right okay so this much point is clear very good can we move to the second method please write two in the chat okay saurabh is saying uh okay how to sort the array uh you can use the inbuilt sort function in pi python okay like you can just search for this thing uh sort function in Python right you sort function in Python you can just search for uh this thing and then what will happen is if I look in vfg so yeah this is there is a sword function so basically what you can do is now you can use dot uh like the Sorting function here so whatever uh whatever array you are having if you use uh like if you are having this number array so whatever array you are having array name dot sorts when you will apply so it will sort the array in the ascending order okay is that clear to uh the python people please write plus p in the chat for those who are clear from python so suppose if I had this list of elements so I can use numbers dot so dot sort also and I can use sorted function also so there are multiple ways of doing it in Python all right so now uh let us move to the second approach as well guys right so the first approach was what method one was based on the Sorting right if I had to sort the array in which I had to bring all the zeros at the front then I had to bring the ones and then I had to uh get the twos after that so basically I have to so I had to sort it ascending order so what was the method one again reminding you about it the method was one was very basic that using the sort uh using the sort function okay using the inbuilt sort function all right now what can be the second uh what can be the second way of doing this particular thing right what can be the second way so if I have to think about the second way of doing this right so uh again suppose that you have been given this array so let me uh write some elements from here okay so what I will do is if I will write uh one here one here then I'll write zero uh then I'll write two here two here and then I'll write 0 and then one okay so if I'll write this particular uh array right in front of you let's say this is the array error that I have declared so what I can do is now there is another uh yes you are saying correct Shalini right you are very uh your approach is absolutely correct so what we can do is if we discuss about the method two so we can do what we can use the concept of the counting sort okay counting sort or you can say count sort so we can use the approach of count sort now what does this mean since there are only three elements that I can have either the element will be zero or the element will be one or the element will be two so so what I can do is that I can keep I can use the concept of count sort okay what does count sort approach means so basically if I know that there is a particular range in which the elements are going to lie so if I know that uh only three elements are going together that is that is nothing but 0 1 and 2 so I can keep a variable like I can keep a variable let's say let's name it a zero initially I'll mark it as zero so I can keep a variable zero that will count the frequency of zeros okay then I can keep a variable once like that initially mark it as zero it will count the frequency of ones and then I can keep a variable let's say two's and I can initially mark it as 0 and it will count the frequency of twos in the array is that clear please write yes or no in the chat I can declare three variables and initially I can mark all of them as zero these variables will help me to count the number of zeros in the array the number of elements that are one in the array and the number of elements that are two in there okay if this part is clear please write yes in the chat so the approach is nothing but Counting sort okay so basically counting sort means what that uh that we will be doing something with regards to the frequency counting okay so we'll be uh if if the range if we know the range of elements right counting sort is based on the concept that uh when we are when we have to sort and the elements that are there in the array they are in a Range please write R in the chat which language is Pets best uh any language the like is best right C plus plus python or Java whichever you have a command on that is the best language okay so guys are you getting my point what I can do is basically I can say that I will do use the countings order Pro so basically counting sort means nothing but counting the frequency of each and every element okay so I will iterate through the array and when I uh so I will iterate through the array okay so let's say if I am at this element so if I see a one okay if I see one so I'll increase the frequency of this uh variable one so now this frequency will become one okay then after that when I move to the next element so let's say I move to this element then again I see that this element is also one so I'll increase the frequency frequency of ones by one more so two ones I have seen that is what it indicates then I go to the next element so it is zero so I'll say that okay the zeros frequency will be increased by one so I will do 0 plus plus so this element will increase to 1. okay then after that I'll move to the next element of the array now this element is one this element is nothing but two guys so if this particular element is nothing but two so what I'm going to do is I'm going to increase the frequency of 2 so 2 frequency increases by one to two plus plus one I'll do so it will increase by one so it will become one then after that again the next element is 2 so I'm going to increase its frequency and it is going to become 2 of after that when I move to the next element so it is 0 so I'll increase the frequency of the element zero so it will now increase to two then after that I move to the next element it is one so the frequency of once increased by one more so it becomes three so is this part clear please write uh best uh source for CPP I think gfg is the best source right so guys yeah you can see here basically how many zeros are there please write two zeros are there how many zeros are there in the array guys please tell me please write two in the chat are you clear with this part guys how many zeros are there in the array two zeros are there correct okay so that is what my variable is telling me okay two zeros are there in the array right how many ones are there in the air how many elements are there that are one so three elements are there in the array that are one okay please write three in the chat now three elements are there in the array which are one correct guys all right thanks a lot malviya thanks a lot saurabh thanks a lot shubham okay now how many elements are there in the array that are two so two elements are there that are two okay so is this also clear so please write two three two in the chat guys okay so basically I can say that two elements are zeros right there are two zeros in the array okay then there are three ones in the array okay then after that there are two twos in the array okay so this indicates something right that how the count sort works so first of all in the count sort what we do is you can observe that we will first of all do what we will count the frequency of each and every element okay if the range was bigger then we would have used an array for counting right if suppose we had to count 100 elements frequency of all the hundred elements then the rsis would have been larger right so here you can observe this thing that what I will do is after I get the count of zeros once and two so since the number of zeros that are there is what two zeros are there three ones are there and then two twos are there so what I can do is now in in this array I can I can say that first of all whatever number of times I have got zeros okay so that many zeros I will fill so since I have got zeros as two okay so I will fill two zeros here okay I will fill two zeros here so two times I will uh run a loop and I will fill two Zeros please write 0 0 in the chat is this clear please write 0 0 in the chat guys so since the the uh there are total two zeros so what I'm going to do is first of all I'm going to fill two zeros in the array okay after that what I will do is I will see that uh there are three ones uh in the uh array okay so uh after filling two zeros I will fill three ones okay so I will iterate for three times and I will be filling one in from the next position so from this position I will fill one okay then at this position also I will fill one and then at the next position also I'll fill one so at three positions I will fill one okay then after that I am having two twos so for the next two positions I am going to fill two 2 and for the next position as well I am going to fill 2. so is this is this part clear to everyone so that is why the final array will be that uh in the final array I'll be having two zeros I'll say two zeros in the starting then three ones will be there and then two uh twos will be there is that clear to everyone okay and if I fill it in the same array ARR so you can understand that my uh time complexity is going to be what time complexity is going to be order of n for first of all counting uh order of n for counting the number of zeros ones and twos and then another order of n for iterating through the same array and filling the zeros ones and twos so the overall complexity order of n plus order of n is order of two n which is nothing but order of n Only order of two n is nothing but consider as order of N and the space complexity you can understand if I'm going to fill in the same array so space complexity can be set as order of one so is this part clear please write yes and CLR in the chart clear plus plus or plus one in the chat if you are acknowledge that you are clear with this right so basically if you don't know there is a there is a approach that is known as counting sort okay it is used for the bigger numbers also suppose that if I had the elements from 1 to 10 so I would have declared an error like I would have declared a map or I would have declared an array uh okay and in that if suppose that they were elements right so this uh is this method clear to everyone till now please write plus one in the chat and please hit the like button guys so that I can get an idea that you are clear right so all of you can uh please make sure to hit the like button if you all have clear with this much part is everyone clear till now or not guys please tell me all right very good so please make sure to acknowledge our effort by hitting the like button guys okay then I will proceed further okay now if you want to uh so so this was a basic idea about the counting sort okay if you want to learn more about counting sort uh so how the space will be order of one Aditya because the space will be order of one because I will say that I will update the same Arena so if I am having two zeros so first of all I'll fill two zeros here so here I'll fill a zero here I will fill a zero okay then I will fill three ones here so one one and one here and then I will fill two to uh two twos here so basically I'll fill it in the same array now that is why uh C sharp as well Bharat uh C sharp option I think uh C sharp option is not added currently in these problems that is one issue the approach uses counting so please write CS in the chat okay see yes in the chat guys the approach uh that is used is nothing but the counting sort approach okay so what uh what I can do is if I will just search for count sort and let's say after that I will write gfg okay so uh counting yeah you can see counting sort approaches here so you can read more about the content counting sort approach if you want so you can see it uh if you will see you know so if as you can see here counting sort I am showing you the definition so this lecture is not only there just to uh make you understand uh just to solve a problem it will uh as I am explaining various approaches that can be there so in this problem uh you can use the counting sword approach and you can see it is based on the keys uh in the specific range so whenever you have elements in a specific range so in our case we add the elements from range zero to three right that is why it works so it works by counting the number of elements so if you want to read more about it so I am just sharing the link of it in this chat okay uh good evening courses so this uh this is a beginner friendly course Yoshi uh in which we are discussing the basic problems okay so currently I'm discussing the count sort after that I will be discussing uh I think I'll be discussing minimum number number of jumps as well and one more problem that I'll be discussing is counting the number of savares with some less than K so if you want you can stay here no worries okay so guys is everyone clear till now okay so this is the counting sort article that is there on gfd so you can read it from gfg okay is this approach also clear please write yes in the chat guys and then I will proceed further also a lot of new people have joined so please hit the like button guys as and also make sure to do one thing for us uh please share it with your friends as well can you please reduce this pizza uh sure I will try to go a bit more slow okay so yeah this approach is also clear now when you are in when you are in an interview you know so first of all you can tell the interviewer about the basic approach that I can do what I can use the uh sort uh sort function and then we can simply sort the array okay then you can tell the second uh in the second approach you can say that uh you can tell the interviewer that I can use the counting sort approach okay after that the interviewer will tell us that can you do can you do in it in one Loop okay sir please choose Python language for solving the problem uh basically uh mostly my uh concern will be on the logic uh personally I uh like I will not suggest that you should think about any language it is more focused on the approach and if you know a particular language then the code is very much simple it is not based on any particular thing please use Java to teach all maybe 3B right uh okay I will try to code it this problem in Java I don't have any issues with that okay so hi siddharthur said op in the chat you can write guys okay so yeah this uh this much point is clear to everybody okay guys now let's move to the next approach that is the third approach right so what I can do here is uh I can say in the method three right uh in the method three that we are going to discuss now in the third method what can be done so in the third method we can at least explain uh I will use Java code no worries I can write the Java code as well okay so yeah now method three is going to be what now the method three is known as nothing but Dutch national national flag algorithm right so it is known as something like this the national flag algorithm okay national flag algorithm all right so the next approach that is there it is known as the Dutch national flag algorithm all right please don't Focus much on the code yeah main focus is on The Logical side of the things only right so yeah the next approach is the Dutch national flag algorithm so what is the idea of this algorithm okay what is the idea of this algorithm let me uh make you understand so what is the idea of this algorithm right so the idea of this algorithm will be that I will keep three pointers okay I will try to uh I will try to use pointers here so suppose if I have an array right so I will try to I will try to use the swapping and I I will try to swap the elements I will try to Interchange the positions of the element in such a way that I will have three segments okay I will have a low pointer okay I will have a midpoint and I will use a high pointer as well so I like I am going to use basically three points and see I'll basically what I will do is I'll try to in this Dutch natural algorithm what we will try to do is we will try to reduce our time complexity to order of M okay we will try to reduce our time publicity to order of N and the space complexity will be order of 1 because we will not be using any extra space right so what will we try to do here basically the idea will be that we will have three pointers let's say we'll have low we'll have mid and we will have the high okay so the idea will be that um okay yeah so the idea will be that what we will be doing is all the like we will try to uh change the elements in such a way right we will try to place the elements in such a way that all the elements on the left of the loop okay all the elements on the left of the low so if we have if we will have three pointers low mid and high so all the elements that are from the index is 0 to low my uh low minus one okay all the elements that are there in the index is 0 too low minus one okay all the indexes that are there from 0 to uh low minus 1 right they will be what all the elements that are there from 0 to low minus 1 uh they will be uh zero okay I will try it this way and then what we will say is all the elements that will be there okay from High plus one okay High plus 1 till the end okay they will be 2 for us okay and so these this these are the indexes that I'm talking about indexes right indexes and all the elements that will be there in between the low to the this thing in between they they will be nothing but one so all the leftover will be one you can understand right so basic intuition will be that all the elements on the left of low you can understand by looking at this that what we will try to do is all the elements all the elements right all the elements on the left side of low or elements on the left of low okay left off the index low the index low will be zero okay will be zero please write 0 in the chat is that clear so this is going to be the intuition what we are going to uh achieve is what we will try to achieve is that all the elements that are there that are on the left of the low index okay all the elements suppose if I have an array right so if I mark this as the low index then all the elements that will be there on the left there will be zero zero zero kind of you can say right so all the elements that will be there on the left of low they will be zero please write 0 in the chart if this part is clear so the idea will be that all the elements that we are going to have uh that are on the left side of the low index okay so they all will be nothing but 0 so suppose if I have this array and this is the low index uh let me write this suppose this is the low index uh then in that case all the elements uh on the left side of low will be zero which part you want me to repeat you can tell me I will repeat that again okay and those who have joined just now please uh hit the like button so that the counter can keep on increasing all right Yeah so basically all the elements that are there on the left side of the low they will be zero that is what I'm saying they didn't get which part you did not get I'm just telling you about the intuition like what is the basic idea of this algorithm that I am telling you okay this is this uh this is Dutch national flag algorithm so basically it uh it works on this idea okay index part so basically what I'm saying is suppose suppose that this is a particular index so suppose that this is what this is index 0 uh I I will use a different color suppose this is index 0 this is index one this is index two this is index three this is index four so let us say that if I will mark this as index low now okay so let me use a different color so let's say if I'll mark this as index low so all the elements that will be there on the left side of low they all will be zero okay all the indexes on the left side of low so if the low is equal to 4 so all the indexes on the left side of uh low uh of the index uh low they will all contain zero is that clear or not what do you think uh is this idea clear now right what I'm saying is what we will try to do is if let's say I keep this as the low index so if this is low in like low index and it is equal to 4 right so basically the idea will be that the low index will be pointing just after the zeros okay so if till the index 3 I'm having zero so low index will be just after that that is what the idea is so all the elements uh from 0 to low minus 1 they will contain zeros okay so on the left side is it it is like maintaining sorted and unsorted uh array uh yeah you can say something like that only but yeah what the idea will be that if I if if uh basically what will happen is we will try to place the elements in such a way we'll try to arrange sort rearrange the elements in such a way that all the elements that will be there from the index 0 to low minus one okay they all will be zero is that clear please write plus one again in the chat if it is clear it is more like France flag uh I think it is known as Dutch national flag I'm not sure there can be different names of it but but we call it Dutch national flag I think okay so is this clear guys is this much part clear all the elements that are going to be there on the left side uh so this low is going to indicate an index of the array and that index will be uh just after the zeroth whatever last zero I'm getting uh so that index just after that I will place my low so low is going to indicate what low is going to indicate about uh this thing about the elements uh like uh just before the index low so from 0 to low minus 1 all the elements are going to be zero okay and what is the other idea what is the other idea so let us say that uh if this index was what five six seven let's say this is eight nine okay so let's say this this I keep as high right suppose my high is equal to seven suppose this is my high so uh or let's say my high is six suppose that my high is uh six okay so suppose this is my index High h i g h okay so After High all the elements After High okay they will be two is that clear all the elements uh like you can I will write this thing again here all the elements okay all the uh like all the indexes oh sorry all the indexes before uh before low before index low will be zero before index low will be will contain zero okay will contain zero so all the indexes that are there before the index load they will contain zero and all the indexes all the indexes after index High after after index high will contain two okay high will contain will contain the element 2. is it clear to everyone guys please tell me so in between you will have this Sigma in like in the between region you will have once if you uh okay so basic idea will be that I will I will always try to make sure that before the low index always we will try to make sure what always we will try to make sure that before the low index uh all the elements that are there are zero after the like and after the high index we will always try to maintain that all the elements that are there are two okay is this part clear so if before the low index if all the elements are 0 and if after the high index if all the elements are one then in between all the elements sorry if all the elements are two then in between all the elements can be set as one right so is this idea clear please write yes or no in the chat plus one in the chat guys and you can hit the like button as well is this clear that is what the intuition is all about so is this much part clear or not please tell me is the intuition basic intuition part clear to all of you please tell me okay so that is what I said if you talk about the indexes right indexes so in the array if you talk about the indexes so what I just want to say is that from 0 to low minus one index all the elements will be zero okay all the elements will be zero again I'm writing this okay so you so that you don't forget it then after this again another thing that we need to notice that's from High plus 1 okay so all the elements after the high till the end of the array okay uh all the elements will be two and in between all the elements will be one right all elements will be 2 okay and uh in the meantime in between all the elements will be one okay so you can understand if you if you take care of this thing right please write yes in the chat agree in the chat if you agree with me if all the elements before low are zero okay before low all the elements are zero and After High all the elements are two so in between you are going only going to have once correct are you are you getting my point if if if before low all the elements are zero if After High all the elements are what two then what is going to happen in between all the elements will be one do you agree with me on this point guys yes I hope that you do agree with me on this part correct everyone does agree very basic uh very basic thing right if before low all the elements are zero and if After High all the elements are two so in between you will have once correct is this algorithm scalable when elements are from 0 to 5 uh this is based on color so uh primarily this algorithm is used for this particular question but uh you if there can be manipulations as well okay is this much part clear please write plus one and then I will move proceed further then I will start running the algorithm for you okay then I will start with the dry run of the algorithm okay guys if this much part is clear you can hit the like button give me a plus one and then I will proceed further so if we are we have apart from zero one two numbers uh as of now we are discussing this problem only uh they can be various like you can change the algorithms and things might vary but uh but it is not scalable when the range is very high then you have to use sorting approach or counting sort or something like that okay then they will they are much better all right so this much point is clear to everyone very good now moving on moving on what we will do is so let me take a very random array okay so what I will do is first of all let me uh let me have this array so just give me a second what I will do is I'll have a uh have an array for ourselves I think uh like I can declare it okay guys so yeah I think uh like this watch part is fine so let me quickly make some indexes here okay let's take a bigger all right okay uh right guys now start suggesting some elements in the chat guys okay uh what I should give you like I have to take some random elements uh in any order so start suggesting and I'll take some of them okay so let's say if I will initially keep what let's say if I'll keep like I will take a different color so let's say if I'll keep uh take 0 here I hope that this color is visible right then let's say I will take one here then I will take one here 0 here 0 here okay then let's say if I'll take uh something like uh what let's say I'll take one here two here then again two then I will take let's say one here one here zero here then 2 here then I will take one here okay then let's say if I am taking what one here as well like is this is this array fine for everyone okay why are you suggesting these kind of numbers 89 56 I just ask you to suggest the numbers between 0 to uh two only okay Praveen okay guys yeah so you can because we are we are not sorting normal are we are sorting this array okay yeah so we will take this array right now initially what we are going to do is we will say that our low uh we will say that initially our low is going to point at the index 0. so let me do the indexing of the array as well this will be index 0 this will be index one this will be index two this will be index three this will be index four okay then this is going to be index 5 this is going to be index six this is going to be index 7. uh this is going to be index 8 this is going to be index 9 this is going to be index 10 this is going to be index 11 this is going to be 12 and this is going to be 30. all right now sir you said that three pointers are there uh yeah so mid pointer will help me to change right yeah so mid pointer will be a floater kind of so I will have low I will have mid and I will have I I know that but basically the mid pointer is going to help me behave like like mid pointer is going to help me to adjust okay it will help me to adjust the elements that is what I am saying it will help me to adjust the elements okay initially uh mid will start from the uh zero point it will help me to adjust will any certificate be provided if you will write in the comments that you want certificate then yes the team can try to provide it okay so yeah initially what will happen guys low will stand at uh this thing okay low will stand at the zero to index so initially you will say that low is standing at the zeroth element index and high is also standing at the index 0 okay so high will also standard sorry I will not stand at 0 mid will stand at zero okay low and mid are going to stand at zero and then what we are going to do is we are going to make the high stand at the very end of the array okay is this much part clear jaldi Karo three problems yeah I will try to do it first next two problems are kind of easy so we will be able to do it don't worry nilu okay yeah so you can see here what will happen is low I will have so people ask me to be slow that is why uh I'm doing I'm going a bit slow are you able to understand guys so we have time so we will have low we'll have mid initially at zero okay low end mid will be initially at zero now what is the uh what is the idea okay what is the idea so what we will try to see is uh can I say one thing guys here if you will see here now can I say one thing uh of how many days this bootcamp is going to be for 21 days okay now if you will see which element is present at a of mid anybody can tell me at the mid which element is present at the mid index so at this index which element is present zero okay which element is present zero so if if it happens Now understand this point of view that uh what happens is if this happens right if it happens that add the mid okay if it happens that you have zero present okay then we will do what we will swap we will swap the element that is present at a of low okay and a of mid we will swap them and then we will do low plus plus and we will do mid plus plus we will move the low and the mid okay you will understand this by the end of uh by the end of the iteration you will understand this okay so initially what no no don't think about the seventh position and all that uh as of now you have to just uh think about this thing why are you writing seven see uh low will be initially at zero mid will be at zero and high will be at the end of the year initially okay then what we are going to do is this is not binary search this is no this is not by any sort also Sonica okay now mid is there okay mid element is there so if at this mid uh I am having a zero so I will swap uh I will swap so actually a of low is what low is also standing at zero you can say that low is also standing at zero and mid is also standing at zero so now what it will I will do is I'll swap the elements at a of low and a of mid so basically this element is swapped with itself so basically no changes will be there and then low and high will move by one okay so then what will happen basically this will help you to move the low and um Mid by one so now what will happen here is now low will come here okay low will also come here and high will also come here okay sorry low and mid will come here sorry so Midway mid is going to come here all right now the moment mid comes here right so can I can I start seeing one thing can we say please write plus one if you agree can you start seeing one very basic thing guys can you start seeing one very basic thing that before the low now zero have started to come right now before low if low is standing at this index now so before low the elements have started to be zero can you see this before load the started the elements are now zero is it clear before low before the index low all the elements are zero can you see this can you start seeing this point yes look correct everyone please tell me in the chat okay please write plus one if you agree with me can you see now before load the elements have started to be zero uh okay now you can see here suppose that uh now my mid is where now my mid is standing at this index okay so my mid is standing at this particular element if this element is one do I have any problem with it do I have any problem with it yes or no no if the mid is standing at one then everything is fine then I will move my mid forward what will I do is if the mid is standing at one submit should move forward now correct it will because uh because I want my mid to reach at this kind of an element 0 because I want to swap it correct I I feel I feel that I feel that this zero should be swept so I will do one thing first of all I'll remove uh the indexing okay I feel that this should be swapped with this guy right these two ways should be swapped so for that what I will do is I'll say that if the mid is standing at one okay so you can see here the mid is standing at one so I will move the mid by one okay so please write mid plus plus in the chat so if the mid is standing at one then I will move the mid by one so mid will move here okay so what I want to write is that else if it happens right else if it happens that if the element at the emitting at the current mid index okay so I'll write this thing else if it happens that a of mid okay if it is equal equal to one then I will just do a mid plus plus that is what we feel okay that is what we will do is that clear so I will move the mid forward okay so yeah it will move forward now and what is going to happen is now the mate is going to move here somewhere okay so now the mid will be here now tell me if it is if if the mid is at the element zero what will we do I will tell you off like I will tell you Gem of 27 don't worry yeah now the mid is standing at zero so what will you do guys please tell me if the mid is standing at zero then we will swap the element at the low index and at the mid index are you clear with this thing we will swap the element at the low index and the element at the mid index okay we will swap both of them is that clear please write swap in the chat okay so what you will do is when you will swap so what will happen is 0 will start coming here okay just a second so 0 will come here and one will come here and then you will move both of them by one forward okay what about attendance uh I will talk about it later on yeah you will move both of them forward is that clear so you will swap both of them okay uh you will swap these elements so you have swap then and then the low and the high will move forward so what will happen now low is going to be here and the mid is going to be here all right so this is going to be the scenario is that clear to everyone guys please tell me okay is this part clear to everyone make sense everybody indeed it does right now again if if you see so again you check so mid is kind of playing like a floater for us right it is playing a floater game for us you can understand now again you can see where is the mid is standing at which element it is standing at can you tell me in the comments please tell me guys in the comments you can tell me and please make sure to hit the like button as well if you're getting the points till now now where is the mid element standing guys please tell me now where is the mid element standing it is standing at nothing but zero if it is standing at zero then again I will repeat the same process okay so if it is standing at zero then what I what I need to do is I will swap okay what will I do I'll swap correct guys so now I will do what uh I will simply swap so if uh I will swap this element with this element so if mid is standing at zero then I will swap the mid and the low so I can say that uh what will happen is 0 will come at the start and one will come here okay and then I will move low and mid by one one each so what is going to happen is uh low will come somewhere here and uh mid will come here all right right yeah this is going to happen after this what will happen is when I see that okay mid is standing at one then please write mid plus plus in the chat now we will do what mid plus plus now because mid is standing at element one so if it is standing at one then I don't have any issues right uh then I don't have any issues so now what will happen mid will stand here okay so this is where my mid will come okay mid will stand now at this particular position okay mid will stand here and now can I say one thing can I say one thing guys can I say one thing very clearly that I have started to observe that before the mid before the mid just before the mid all the elements are zero can I say this can I say this before the mid all the elements are zero please write yes in the chat okay is that clear sorry before the low very sorry before the low all the elements are zero sorry before the low or the all the elements are zero right that is what we wanted before the low yes so before the low all the elements are sorted yeah sorry before the low all the elements are sorted all right very good now after this when you uh will move to the next uh index okay so you move to this index so mid is standing here mid is standing at two so what will happen you will go to the else part right you want what you want this guy to move here now correct can I say this you want this guy to move somewhere here so like let give me a second let me make this element a zero okay yeah now what you want to do is you will tell me that uh now what you will want to do is you will want to swap uh this and this guy correct else what you will do is like otherwise if it is zero like if the mid is standing at two right if the a of mid is 2 okay then you will do what then you will say that you will swap what you will tell me that okay let us swap what let us swap a of mid okay with a of high that is what you will tell me okay so when you swap these two elements then what will happen so basically you are going to swap these two so what will happen here is you are going to bring 0 here okay and you are going to bring uh two there okay that is what you will do now can I say that I will do hi my minus minus for sure I will do high minus minus for sure that is one thing that I will do high minus minus for sure so let me say that I will do high minus minus so one thing is for sure that I will do high minus minus so I will move here so one thing that is sure is that I will do high minus minus but will like some people are saying mid plus plus okay so will you do a mid plus plus that is what you need to think will you also do a mid plus plus guys think about it think a little bit about it do you will you also do a mid plus plus think about it because uh because if you see now if you will see so if you will do a mid plus plus now so suppose see if if you had a one here then suppose that if if at that place you had a one and you have you had swap the one here okay so here currently you are having a zero suppose you had a one here right instead of this if you had a one here then mid plus plus would have been fine but here you can understand one thing guys that if you do a mid plus plus and you are standing at a element zero now so if you do mid plus plus then what will happen now understand this thing kalyani and everybody if you do a mid plus plus then middle will move here okay and then then this zero will be skipped then this 0 is skipped so in between there will be a problem is that clear so that is why you should not do a mid plus plus is that clear to everyone please write yes in the chat if if after swapping if you get a zero here right then it will be a problem for you because you will do bit plus plus so you'll move to the next index so you will move uh here and you will skip this guy zero so that is why you should not do a mid plus plus is that clear to kalyani and everybody right so mid plus plus is not uh going to be done here is that clear to everyone guys okay is that clear uh please hit the like button and give me a plus one if you are clear with this part guys okay everyone is clear all right very good so now what we are uh going to uh do here is we uh we will simply say that now we will move forward okay sorry now mid will not change so mid is here now since mid is standing at zero so what will we do guys since the mid is standing at zero so now we will swap the uh low and the mid so uh now what will happen uh zero will start coming here sorry so zero will start coming here and one will come here and then I'll swap both of them so sorry I will increase both of them so now my low is going to stand here and as far as I can see my high will come here okay now guys tell me what will happen now okay now high is standing here okay uh sorry very sorry mid is standing here very sorry yeah now mid is standing here so now mid is at two and high is so mid is if middle is at two then I will swap these two elements okay so what I will do is I'll swap these two so you can say one thing that one will uh start coming here and two will be here okay and then after that I I will do a high minus minus so what will happen here is a high will start coming here okay I will be here all right uh so yeah this is what is going to be done and uh let me do one thing more let me put uh 0 here and 2 here okay so this will be better yeah now if you see uh high is here so after that made it standing at one so I will move it forward so mid will come here then it is again standing at one so mid will come here okay after that what will happen suppose that what I do is uh if I stand with my mid here right if my mid stands here right now what is going to happen guys right now if my mid stands here so mid is standing at an element which is two so which elements will I swap I will swap which elements guys please tell me now uh I have put a zero here right so uh like let uh let me just restore the things uh let me say that uh this was two and this was one only uh okay fine because I change in between Yeah so basically after this point if you will see uh like I think I have changed a few things that is the issue uh okay let me put a two here okay now suppose that you were here right then you will move here afterwards okay so your uh hi was there uh after that I think I did not decrease my high that was the issue with my code okay yeah so I will come here okay then by moving one by one the mid will come here okay so again you will see that when I will uh when I will again swap because uh I'll swap the mid and the high so now what will happen uh one will come here and two will come here okay then I will do a high minus minus so basically you can see that at this place mid will be there and at this place I will also be there okay so you can see that just before the the high all the tools are there okay and uh just before the low all the zeros are there and in between all the ones are there so that is how the arrow is getting sorted okay is that clear to everyone please write yes in the chat is this clear please write CLR in the chat but it was Zero at no no no kalyani I had changed some elements here and there so don't don't worry about that okay overall when you will sort so the same thing will be there uh later on now I had changed the array a little bit so don't worry on that part yeah even if you keep a zero there also then also it is going to be fine uh where do you want me to keep a zero uh foreign see if you if you will say that suppose that somebody will come and tell me that let's say we'll have one here okay and somebody is going to tell me that let us say we have one here also and let's say we have zero here okay then I will tell him that uh since my uh see in that case what will happen my high would have been standing here okay and I when I will uh check for my mid so uh my mid will be here right now if if if suppose that kalyani is talking about this particular scenario right so in that case what will happen now you will say that I am in trouble no because now I will swap these two guys okay so what will happen uh a high end this guy will swap so at the mid index 0 will come and at the high uh one will be there okay then after this particular Point okay after this particular Point what will happen is uh when I will do a high minus minus so obviously my high will come here you can say that now my mid is here so since my mid is standing at zero and low is standing at one now so the swapping will be done so so in that case what will happen the swapping will be done and you will see that zero will start coming in and one will start coming here so for that and then obviously both of them will move by one each so you can say that low will come here and mid will move forward by one so mid will come here and you can see that just before the low all the elements are zero just after the uh and you can also see at the same time that after the high all the elements are two so like is this idea clear or not that is what I wanted to say maybe I missed some of the part in between but uh is this clear or not right overall intuition is clear for this algorithm or not guys is it clear to everybody yes or no then I will start writing the code also okay so what we need to do is we can simply say that we can run the loops okay so yeah now now the thing is that we just need to run the loops so how will we start with the loops anybody can tell me in the chart guys anybody would like to tell us how to do it right guys anybody so while the high and the low do not cross each other till that point of time you need to run so you can sorry mid and the uh high do not cross each other uh so what I will do is uh while uh sorry initially I will mark my low as zero and I will mark my Beta 0 as well and I will mark my high as uh this thing high as n minus 1 okay that is what I'm going to do here now one doubt what is the doubt you can tell me don't worry after class watch two times everything will be clear all right just give me a second then okay yeah so after this what we will do is we will simply say that mid is what less than equal to the high okay and then what we are going to do is if it happens that uh a of mid okay if it is equal equal to 0 then what I will do is I will swap the element so swap a of mid with a of uh low okay and then what we are going to do here is yeah while made is less equal to higher that is the case actually yeah so what that is what you are writing did you just join okay yeah so this is what we are going to do and I will say that hi sorry I will say low plus plus and then I will do met plus plus as well just for a second okay is this part clear to everyone guys I'll check what we will do is suppose if at the mid uh okay if we are having a one then in that case what I will do is I will do this with plus plus okay so I'll just move my mid otherwise what I will do is uh suppose that if I'm having two so if I'm having two then I will do what I will swap a of uh mid okay with a of uh hi guys okay with a of high and then what I'm going to do is I am going to do high minus minus okay that is the only thing that is required and you don't need to return anything because there is no return type so array will be checked in uh in the meantime uh mid plus plus will not be done keep smiling okay a of low I think I need to mark this as l o w sorry yeah now let's try and run it is it clear to everyone please write plus one yes spelling mistake I am clearing it no I will write it okay uh is it clear to everyone guys yeah I am correcting it as well yeah it does work let me try and submit it and see if it gets accepted or not so it does get accepted right so is this problem clear to everyone and you can see that what will be the time complexity so the time complexity is just going to be order of n okay you can see the time complexity or of our approach will just be order of N and space complexity is nothing because we are not using any Extra Spaces space complexity is order of one so is this part clear can you do it for value four uh as of now I will not uh try anything else because I have to solve two other problems okay so just give me a second is it clear to everyone guys all right uh I don't I think there is no function in Java techy bytes but you can use the normal sort normal swap approach there okay uh is it clear to everyone please write clear in the chat plus one in the chat guys then we'll move forward to the next set of problems as well I've shared the code uh link with you okay and this is the problem that you can try to solve okay guys can we move forward to the next problem then all right I think that we can move the to the next problem okay so let me solve the third problem first of all I think it is a bit easier for us so that we can spend some time on the second one okay so yeah just a second let me now solve the third problem that is given in the link so count the uh sub arrays that is given as the third link rubber is with this product product less than okay right less then okay okay just a second and uh I will get this link okay yeah count the Subarus having product less than K okay sorry okay so using third uh can we start with this please complete all problems today yes I'll complete all problems today so can we move forward guys please write plus one in the chart okay can we start with this problem as well plus one yes in the chat [Music] all right so let us move to this particular problem guys okay now if you will see this particular problem count the Subarus having product less than K so suppose if you are given this test case okay so now again if you see this problem as well so I think this has also been asked in some of the companies this has been asked in Goldman Sachs right so you have to count the subares with product less than K okay count less than k who have the product less than k less than k okay can we do this with sliding window yes like kind of sliding window is the approach that we have to use here shall any right so guys you can hit the like button now let's uh start with this so suppose that if we are given this particular array okay just give me a second let me write this so let's say we have one here then we have two here then we have three here and then we have four here okay if we are having these elements and we are having the K value as 10 right if you are having this and the K value is 10 here okay so in that case we have to see all the survivors which have which have the product less than uh okay so I can say that one alone is a sub array that is having product less than K two alone is having product less than K three alone is having product less than k then I can say that four alone is a Subaru that is having product less than k then one comma two is a sub array with product less than k then one comma two comma three is another uh with product less than k then I can say that uh two comma three is another sub array with product less than K okay so one two three four five six seven so does the answer seem to be seven yes you can see that the answer is seven so is this part clear guys are you able to see that the answer is seven please write yes is it here so this summary is having product less than K right so if you just take one element This Server is having product less than okay this server is having product less than okay this server is having product less than okay one comma two is having product less than K one comma two comma three is another sub array from here to here that is having product less than K okay then this is another Subaru which is having product less than okay okay Sonica which party you are not clear with no you will not it is not a subset problem it is uh it is not based on subset okay so how will we solve this problem anyone can tell me in the chat anyone can tell me how will you solve this one now in order to solve this problem one thing is the two comma four no no you will not choose if you are talking about Subarus no vigneshwaran if you are talking about savares then you have to take in the contiguous sequence okay so if you are talking about savares so if you want to take two and four so you have to take three as well so you have to take in the contiguous uh sequence 3 4 will give the product as 12 no this this and this element will give the product as 12. the product of this will three if you take three and four so their product will be 12 which is not less than k n so the product should always be less than k okay double listed Loop yeah we can use what can I say that we can use a nested Loop right so we can have C what I can do is if I have to generate all the sub arrays no right guys so you can see here suppose that if I have to generate uh all the Subarus so I can have I here J here so one of the survivors will be one I will be able to check its product okay initially I'll mark the product as one then I will move here so I will multiply the product product will become two it is also less so I will count it as well okay then after that I will move my J here so now the product will total becomes 6 right so uh I will count it as well so the count will become what three so let me say that I have a counter so now the counter is going to become three so in that case I am counting I'm counting one one comma two and I have also counted one two three as well right then after that when my J will move forward so let's say J moves here then the product will become what uh 24 so it is not it is greater so I will stop are you getting my point so then I will stop is this part clear guys or not please tell me please uh is this clear till now then I will stop so I have only counted this right so when I was here Jay was here so I counted one then after that when my my J moved there so the product became two so one one Commodore the product became two so for p was two so I counted this as well then my J moved here so product became six so indirectly I did a counter plus plus again so I counted this particular sub array is that clear guys still now guys please tell me till now are you getting the point okay then after this where uh when you will uh when you will uh move forward so I will be here Jay will be here so initially the product will be multiplied with this element so product initially was one now it will be here too now uh again you can say that this is another Subaru so you will count this as well so the counter will now become four okay then after that when you will move your J forward so what will happen is when you will move your J here then the product is going to be what total product here is going to be six of two and three so you will count this as well so now the count will become what it will become nothing but five after that when you will move uh again so J moves here and now the product is going to be 24. so you will not count it and you will stop here after this what you will do is your I will start from the next index Y is going to start from here J will be here so product is going to be 3 initially at this point correct guys yeah 24 is greater that is why I'm not counting it yeah that is the reason why we are not considering it keep smiling okay so then I'll uh I uh my uh I will be here Jay will be here so the product is what it is going to be three so I'll consider it so now the count is going to be six and I'll consider the element three as well alone okay after that what we will do is if my if I move my J forward so J moves here now the product will be what it will be 12 okay so since the product is 12 so uh it is greater so I will stop I will say that I cannot count it because the product has to be less than k then after that my I will be here J will be here so product will be only four so I can say that uh what will happen is this product will be counted and account will become saved so actually this one is counted is this clear can it be solved with sliding window yes I will always using sliding window only so is this much part clear so basically if I'm running a eye Loop and like I am running a i Loop uh okay then I'm running a j Loop starting from I till the uh end of the error J is less than N I start from 0 I is less than n so basically the time complexity will be what if I'm running two Loops one inside the other so the time complexity of the Brute Force approach will be ordered of n square and the space complexity is going to be order of one correct guys is this much part clear to everyone please tell me then I will proceed further okay and please hit the like button if you all of you are clear till this much part okay if all of you are clear till this watch part so you can write yes in the chat and then I'll proceed further okay I have a question about Dutch national flag so we can easily divide uh if there are more than three so you can use the counting sortner so that is why I've shared the counting sword approach Praveen you can go for the counting sword approach in that case because I'm not using any extra space no space complexity is order of one because I'm not using any extra space I'm not I'm not storing these I'm just showing you for your uh confirmation I'm not storing this okay so is this much part clear right guys uh is this much part clear can we move to the second approach this was the method one okay method one you can see uh kind of brute force in nature so thank only three would be order of L square space complexity will be order of one is this much part clear please write plus one guys and let's see if we can reach 160 likes or not and then I'll proceed further okay can I proceed further now okay please write yes in the chat or next in the chat then I'll move to the next approach please write text in the chat and also please give me a plus one in the chat and if you haven't hit the like button so please hit the like button also so that our reach could be maximized all right thanks a lot kalyani now what I will do is now I can do what I can use the method too okay so method two that I am going to use it is kind of going to be a sliding window approach okay sliding window approach you will understand it don't worry sliding window approach okay so how it is going to work let let me tell you okay so what we will do is uh first of all let me uh have the array here okay so let's say this is the array one two three okay let's say I have this as one this element is two this element is three this element is 4 and as always K is given as 10 in this case right now in this particular scenario what we can do is next plus is equal to one very good yeah now in this case what we are going to do is we are going to take initially a product variable initially as one let's say we will have the product variable initially as one okay we'll declare it initially as one okay then after that what I will do is uh I will uh say that initially we are going to start okay so we are going to have a left pointer like we are going to have a starting and ending or you can see our left and the right pointer so left will start from 0 and okay so we are going to have a left index on the right index initially of them are going to start from zero is that clear so we'll have left and I right here is this part clear guys please tell me okay initially left is going to be there and right is going to be there is this much part clear okay guys yes or no all right yes it is clear very good now what I have to do is now what I will do is I will simply say see I will I will simply have a look so if I will currently look at this particular guy okay so this guy is one so I will say I will always consider this guy as a of R right because uh R is going to be the element that I am going to consider R is always going to move one by one so R is going to be there this will be a of R okay now if this is uh the element so if I'll multiply it with the product what is going to be the product what is going to be the updated product anybody product is still going to be one because if I have multiplied one with the product so product is going to be one okay product is going to be one now what will happen is then you can say that this this particular sub array is there okay which has the starting at this and the ending is this so can I say that this one is a subarian like this is a sabare which is having the product as one uh like which is having the product less than K you can see that the product is less than K okay if the product is less than k then I can say that uh how many how many subvers I'm counting one sub array how so if the R value is 0 and the L value is also zero so I can say that R minus L plus one number of sub errors I'm counting so you can see that initially I'm counting only one sub array is this part clear please write one in the chat at least write one at least I'm counting this one then I will proceed further and you will know this okay then I will definitely when when all will move to the next index then you will understand it better can I can I proceed further all right so what will we do here after that so after this point when my uh left left is here and then my R moves forward so L is here now my R will move here so now what is the updated product anybody can tell me now in the product I will multiply a of R so what is going to be the updated product guys please tell me so now the updated product is going to be what the updated product is going to be nothing but two okay and is the product is the product lesser than the K value yes the product is less than the K value and since the product is less than the K value so in such a situation I can simply say that if the product is less than the K so I can say that I will count the value as R minus L plus 1 why because if you see L is L is 0 R is 1 okay so then I will count the number of sub viruses R minus L plus 1 why because 1 minus 0 if I will do plus 1 so overall I am going to get 2 why because initially I counted what initially I had counted uh just give me a second what I will do is I'll show you so right now the product is 2 correct guys right now the product is two if you will see what I did was I did Count uh plus is equal to uh what initially I did 0 minus 0 plus 1 okay so in that case I was counting which uh which server I was counting this one sub array then after that what happened was count uh like after that the count plus is equal to what I am always going to do count plus is equal to R minus L plus 1 okay so now I am doing one minus 0 plus 1 so this is I'm in this case I'm counting two more Subarus so now you can see here basically I'm counting this sub array 2 and this uh one comma 2 also right so if now just L and R are here so indirectly I am counting this also and this also one comma 2 also is that clear please write yes in the chat please write plus plus two so total count will become what three are you getting my point because initially in the counter I had added one now I'm adding two So currently the count value is what it is three is this clear please tell me in the chart guys please write three in the chart okay labina is saying that she is clear uh guys let's make it 160 likes if everyone is clear till now are you guys clear with it or not let me know okay you can write clear in the chat can we reach 160 likes if you are clear with this watch part uh please let me know if you are clear with this much or not okay so people are clear which part you want me to repeat basically uh when L and R were standing here when L was here R was here then I counted uh R minus L plus one so zero minus zero plus one so I counted uh the this this like this that is just one right I counted this particular sub array that is just one you can see here I counted this particular sub array that is just one okay after that uh what I did was I counted this about it two and this one comma two okay so that is why I counted two Subaru so you can see one minus zero plus one so R minus L plus one now it will give me the value as two so two mores of RS will be added right so in so my counter is actually my counter is now three are you getting my coin guys so actually my count value is three basic idea about this sliding window so yeah is it clear now neeraj or not and everyone else also so actually you can see my account is now storing three subvers because I've seen three suppliers now is that later everyone else please tell me then I will proceed further as well okay okay guys please hit the like button for those who have joined just now let's see if we can reach 165 Flex or not okay please hit the like button guys and then we will proceed further to the next part okay let's see if we can reach 165 likes or not for those who have joined just new uh please make sure to hit the like button okay all right now yeah you can see here uh L minus r plus 1 idea is clear the number of sub errors in a Range if if you have Ln R so in that R minus L plus 1 will be the counting that I I will be doing it is different from the previous one yeah this problem is a bit different from the previous problem exactly right then after this when my R will proceed further so my R moves here at this place right so the moment my R moves here so R will be equal to what 2 right now here what will be the product so whatever product was still here into a of R right so now the product will be what the updated product will be six okay so now the product will get updated to six and you can see the product is six so this means still here the product is six okay and it is lesser than K value so again I will increment so how much will I uh how much how much the virus will get added can you tell me R minus L plus one number of Subarus will get added okay how many Subarus will be getting will get updated so you can see that what I will do is I'll do count plus is equal to R minus n plus 1 so 2 minus L is 0 plus 1 so total three more suppliers are going to get added so count is equal to count plus three okay so current count is three plus three so total it is now going to be six here okay why it it is uh total three more survivors will be added why because if you see now we are considering with a virus if you see we are considering the sub array one two three okay like this particular one two three okay then you are also going to consider the sub array two three okay so you you are also considering the solar two three and you are also considering the single server three so is this part related to everyone guys please tell me uh is it is it clear to you uh focus on the logic needed you will understand it you can see with Subarus I am able to cover because of this no if I am doing R minus L plus one here so I'm able to cover one two three sub array I'm able to cover two three somewhere and I'm able to cover this three somewhere so that is how I am covering it is that clear guys please tell me three then one yeah one two three is one Subaru then another software is two three and another one is three so that is why R minus L plus one is doing the job for me please write plus one in the chat guys if you are able to understand it are you all able to understand this much part a picture is saying yes very good a picture okay now after this my R will move further so our moves here now okay so R is equal to three now all right so when the R value is equal to 3 here so I am always doing R minus L plus one for your reminder okay now when the r moves to 3 then what am I going to do so I am going to multiply into a of R so now the product is going to be what guys tell me now the product is going to be 12 okay so uh you can see that the counter will get updated to six now okay so indirectly you can see that the counter will get updated to six okay now the product is 12. so is it less than K uh sorry now the product is uh 24 24 yeah sorry the product will be 24 sorry so now the pro is the product less than is the product less than K yes or no is the product less than k no no please write no in the chart is the product less than k no the product is not less than K okay so this means basically I'm considering this much cement so this product is not less than K correct guys so which pointer should I move I should move the left pointer now okay please write L plus plus in the chat okay so what I will do is this element that I am having currently here now I will say that now I will like see currently I am considering this much segment so I will say that now I will try to consider this first segment so for that whatever element is here I will divide the product by that because I am leaving this so before doing L plus plus I will divide the product by the element so the element is 1 so I'll divide it by one so it will still remain 24 okay so this will still remain 24. now L will come here so L is equal to 1A okay so uh L has come at this particular place now if L has come at this particular place guys right now if L has come at this particular place so please tell me is the product what is the product now what is the product 24 now please write yes what is the product of this segment guys 24 uh three into two is six six into four is what 24. so the product of this segment is what it is nothing but 24 and you can see that 24 is still not less than K okay so the product is 24 and it is still not less than that less than 10. so which pointer will I move I will move my L pointer again so before moving since I am leaving this element now so I will divide this by 2 okay so I will do divide by 2. so whatever element is here I will divide it by that element so since I am dividing by 2 so now what will be the updated product so now my L will move here and the updated product will be 12 okay is this part clear so now what happens my product is equal to what 12. now please tell me so this is the range this is L this is R now is this uh can this be considered yes or no please write no in the chat because uh still the product is 12 so I cannot uh I cannot consider this as well I cannot okay so then I have to again move my L forward so I will move my L until the product is uh not if the product is greater equal to K so I I have to move I have to keep on dividing okay so then what I will do is I will do division by three that is the element that is there so now the product becomes six so when I will do that so what will happen is uh L will be here and R is also here right now what is the product now the product is uh sorry nope product will become four sorry so yeah product when the product becomes four now correct guys so now the moment the product becomes four so it is less than K so I will do what R minus L plus one please write yes in the chat okay guys so I will increase the count by R minus L plus one so when I increase the count by R minus L plus 1 then uh L is standing at the index 3 R is standing at the index three so three minus three okay uh plus one when I will do so uh the count will get updated by what count will be equal to 3 minus three plus one so actually the count will get updated by one itself because only I am considering this sub error that is that is four only okay and the count will get increased by one so now the updated counter value will be 7 and after that when you will do R plus plus so what will happen R will come here and you have to stop because R has R has reached the end of the array so then you will stop okay so then you will stop and the count is nothing but seven so is this clear to everyone this is the sliding window approach is this approach clear to everyone please write 7 in the chart seven op in the chat here op in the chart as well if everyone is clear till this point of time uh is everyone clear till here please tell me in the chart guys okay can we reach 165 likes guys yes or no okay clear okay guys is this uh clear to everyone so you can see what is happening uh what is happening here right uh is this clear till now right everyone please write here in the chat I want all of your confirmation if you are clear right so you can see when the L was at 0 and R was at zero so basically we were considering this one okay when the L and R were here after that what happened when my L moved here and R moved here so then we are considering this first region that is one and two and then only two okay so we considered basically one and two and only two so we count we increase the count by two basically uh L minus uh sorry R minus L plus one so uh one minus zero plus one so increase it by two then after that L is here R is here so this was segment so this one segment is what uh R is 2 and L is zero so 2 minus 0 plus 1 will be adding uh adding uh two minus zero plus one will be three so basically I'm considering one two three okay you can understand I'm considering one two three that is this one then I am considering two three and I'm considering three okay two three and I'm also considering three so I'm adding it like that okay afterwards when I had moved later on so L and R were here so I'm considering only this one so four so total I am considering all the seventh of arrays please like plus plus in the chart guys if everyone is clear uh okay like plus plus in the chat guys everyone can like like hit the like okay so please if you're clear till now please hit the like button and please like plus plus in the chat as well okay like plus plus in the chat everybody and if you're clear please give me a plus one or clear in the chat all right so a lot of people are saying clear but you are not increasing the like can you also take an example uh this actually actually this example was given so that is why I had taken it but uh as you can try to run this on the second example okay and if you have any problem you can tell me but uh I have lack of time so that is why but the approach will be the same okay you can take any array the approach will be still the same uh I won't be able to dry run it because as of now okay now one more thing what will be the time complexity what about the time complexity guys right you will think that okay what is going to be the time complexity right so if you will see if you have an array right let's talk about this array so suppose you have this particular array so can I say that your R starts from here and R is ending here so can I see that because of R you are having order of end time complexity right you are having order of end time complexity because of R correct because R will start from here and R will end at at this place correct okay then can I say that my L is also starting here okay and only one time L is moving from here to here so L is also moving at the end so L will also take in the worst case order of n time so order of n time in the worst case because it is running only one time it is not running repetitively so it is not a nested Loop understand this so yeah order of n for this and Order of n for the L uh L pointer as well so both the pointers are moving through every index exactly one so order of n for this and Order of N Flow this so order of n plus order of M okay so that is why it is going to be you can say order of 2 in which is considered as order of n Only so the time complexity is going to be order of an only linear time complexity is that clear guys and the space complexity is going to be order of one because I am not taking any extra space is this clear to everyone or not uh time complexity and space complexity is clear guys or not please tell me everyone is it clear or not time complexity is going to be order of n Only why because uh order of n for the L is if you see the throughout the code so L is moving at each index exactly one so L is moving uh order of n times at the most and l r uh so L is moving at order of n times at most and R is also moving order of n times at most and they are independently moving right so they are not not nested together so that is why it is order of n please slightly linear in the chat okay so the time complexity is nothing but linear and the space complexity is order of one that is constant space because we are not taking an extra space right we are not taking any extra space not taking any extra space because we are not declaring any extra array or we are not declaring any extra data structure what is the difference between order of 1 and Order of login order of login happens when you sort or when you uh when you divide by two when you multiply by two or multiply by any number then login happens okay yeah so is this much Point Clear to everyone guys please tell me then I will proceed further can we proceed further I hope that we can so what I will do is initially let's say I will declare a variable long long product initially as one okay and I will say that in let's say the L will be at 0 and R will also stand at 0 so give me a second let me write it and then what I will do is I will say that while okay while what I will say is that the right is less than the size of the array our pointer is less than the size of the array then I will say that product is equal to like I will multiply the product so product asterisk is equal to uh what a of R okay so I'll multiply this particular element and then what I'm going to do is I'm going to write a loop because I I might have to move the left pointer repetitively please write rep in the set okay it might happen that I might have to move the left pointer repetitively so I'll check if the left is less than the size of the array and it happens that uh the product okay and the product is greater than or equal to k then I will do what I will say that product uh uh divide is equal to okay I will say that product is equal to product divided by what divided by a of L so I'll divide the product by that number and then I will do a l plus plus because I might have to do it repetitively now please write rep in the chat is that clear I might have to repetitively move the left indexes if you remember this particular problem so what happened here in this problem if you remember so my uh R was here and L was here okay so in that case my product was what my product was uh I think 24 so I move my L here then L here then L here and I keep on dividing so I have to run a loop sometimes right repetitivity in order to uh do it is that clear guys okay so this is why what we are what we are going to do is we are going to do L plus plus okay if the if L is less than the size of the index range and product is greater equal to K so I'll always keep on dividing the AFL and I'll move left okay and then since I need a counter as well to return so initially I can Mark a counter right initially as 0 and then what we can do is we can do ground plus is equal to uh R minus l okay R minus L plus 1 so like you can also write it like round is equal to count plus r minus L plus 1 and once that is done then I also need to move my R so I will do R plus plus as well okay because R also keeps on moving and at the very end I can just return the counter so is this part clear guys to all of you or not please tell me product is less than no uh yeah so basically if the product is greater now so I'll uh if the product is greater equal to K so then I will keep on dividing so I I will reduce it so when I come out of the while loop so always the product will be less than K itself if if after multiplying If the product is greater then L will keep on moving so let me move forward and L is going to take order of end time because it is going through the area exactly once and R is also going to the array exactly one so only order of n time overall R minus L plus 1 yeah so is this clear to everyone guys uh please tell me then I will do R plus plus also and I'll return the counter like make sense to everybody yes or no guys have you enjoyed this problem or not okay so I think I have a minus three mixture I have not returned the counter sorry we need to return the counter here product is equal to product divided by 10 please product divided by a of L basically which part you want to ask Rashmi Singh product is equal to product divided by 10 I am dividing the product by a of L okay by the left element because before leaving I have to divide I have to since I'm leaving that element element a of L so I have to reduce the product by this much and then I will move my L forward before leaving so let me try and submit this to see if this code can get accepted I hope it will get accepted only uh okay it does not work why uh is there any mistake from my end sir no no this is not uh no that will not happen so if the N value is 3 and the K value is 1 so what is the issue here uh have I done any mistake here shall I take anything else your code's output is this much R minus L plus one am I missing something L is less than n and 9 23 samjado basically just give me a second first of all I have to correct it Rashmi so which part I am missing here if the product is greater equal to k then I have to do this I think what I should do is maybe if the product is less than it might happen that the single element might exceed so that is why so if the product is less than okay so let me put this condition then I think it will work fine on the samples and everything uh it might happen that single element might also be greater enough so that is why there might be an issue with that so yeah it is better to check if the product is less than K after that then I will do this yeah so it does work so you can see it gets accepted is this part clear to everyone guys till now it yeah it is only multiplying a of r with yeah I'm just multiplying like always I keep on multiplying the right Element no the right element yes it will only multiply the right element then uh before leaving the left element are you getting my point if suppose if you see this case right so if you will see this case go to 11 I will just quickly show you this case how how it is going to work okay so you can see like if my L was here understand this point guys if my elbows here and my R was here okay so up till now my product was what till here the product would be calculated as 24 then if uh I can say that I cannot afford because I have to be 10 so I'll ask my L to move forward from here and before moving that remove this element so if you are removing this then instead of multiplying you have to divide you have to do the opposite so now the product will become 24 and L will move forward so now L moves here to this element now when L moves to this particular element now I'm telling it to Rashmi so now L moves at this element so now again you can see that uh the product is of these elements is still 24 which is greater than uh greater than equal to 10. so again I can say that I have to remove this element also so from the product so if I have to remove this element so basically I have to divide the product by two so now the product will become 12 so you can see so that is why my L will also move forward so L will come here so now the product of uh this thing is going to be uh what uh three into four that is 12 you can see the product is 12. now since the product is 12 it is still greater no then what you will do is uh again you can see that you have to remove this element so you will divide it by 3 before leaving this element and then you will move your left so left now moves here so now the product will be 4 Which is less than so now you are going to count this much range so basically now you will do R minus L plus one so this will be added are you getting my point is everyone clear with this please write plus one in the chart guys if everyone is clear till now is there anyone who is not clear with any part please tell me this is not this is not a normal while see this will only fasten the process this this while loop is going to help you to skip all the else right so it will and once the L moves it will it is not going to run again and again for for C it will only run this L will run here here one it once it runs here so it will not repeat so at most L is going to take only order of N iterations and R is also going through the array only once right it is not going to move back so that is why the overall complexity for the L is going to be order of N and for r n Only so it is linear only please write plus one in the chat and please please guys hit the like button if you're clear right please hit the like button if you are clear with this part right then I will proceed further what is the time quality I have already uh told this much part so is it clear or not then I will move forward to the last problem as well okay okay is it is it clear to everybody guys now please hit the like button and uh give me a plus one as well can we reach 200 likes okay so the like Target is almost close to 200 can we reach 200 likes let's see okay so enjoyed this problem please write new in the chat this Camp help us a lot thank you sir uh let's see uh yesterday Siddharth hazra was present but did you like my session as well like I hope that I was able to satisfy uh the level which he had uh established yesterday right so yeah I will you I I I'm doing a lot of dry run right so that is why I'm taking a lot of time but I hope it does help you a lot okay so yeah let me try and run this please write new in the chat did you learn something new from these two problems if you did please write new in the chat guys if you have learned something new from this particular session till now then you can write new in the chart okay and I'm sharing this particular code as well so this was the third problem actually but I did it earlier because it was an interesting problem okay you can everyone can write new in the chat at least this much I expect from you that you can write new in the chat and now I think the last problem is what that we need to Dutch national flag very good if you learn the Dutch national flag okay so I think now the last question is minimum number of jumps uh gfg practice I'll write okay yeah so this one is also done old okay old nothing new no worries okay all right so let's move to the last problem now for today okay again you can see this is also a very good problem so yeah let's add also one more thing guys uh if you will go to the description of this video so I think gfg has uh mentioned all the live courses like that they are having live courses and all the other courses that they have so you can check out the link okay after the problem three there is a link for checking the courses so you can click on it and you can check out them all right now can we move to this last problem okay please write next in the chat everyone and then I will start with this one as well and please hit the like button if you haven't already because this is the last problem so let's be more energetic now okay next in the chat everyone can we move to the next problem the last problem so what is the last problem say what does the last problem say right so last problem says that tell me minimum right minimum number of jumps right minimum number of jumps to reach the end okay no number of jumps to reach the end okay uh this is the question minimum number of jumps you have to tell the minimum number of jumps in order to reach the end of the array okay so what does this problem say actually uh let me take a smaller test case first of all so let me take this particular test case uh what I have been given is let's say if I have been given one then I have been given four okay then I have been given three okay then we have been given what two then we have been given six and we have been given seven okay so in this case suppose initially you will start from where initially you will start from this particular element okay what is the value at this particular element anybody can tell me what is the value at this particular element anybody in the chat please tell me what is the value at this element one the value at this element is nothing but one so if the value uh is 1 then maximum I can take a jump of one whatever is the value at this particular element you don't need a DP approach pratik uh you don't need a DP approach for this okay don't worry yeah so the maximum jump that you can take is of one only okay if the value at this element is one then I can take a maximum jump of one only so uh like yeah I will take a jump of one okay I will go to this guy now what is the value at this element guys please tell me so up till now how many how many jumps I have taken so up till now the number of jumps that I have taken is only one okay so initially I started from one and I have taken a jump of one let's say and I went here so now you can say that I am starting at this particular point right now the value here is 4 okay so if the value at this particular element okay if this is 4 so this means that from here either I can take a jump of one okay or I can take a jump of 2 okay or I can take a jump of three or I can take a jump of four okay so when the value is 4 so it tells me that from here either I can take a jump of one either I can take a jump of two three or four right so all the jumps from one to four are possible for me is that clear so from here either I can take a jump of one okay or I can take a jump of two okay or I can take a jump of three or I can take a jump of uh four so I will reach here so please tell me if I take a jump of four so can I say that I will reach the end yes or no if I take a jump of four only right I can take any of only one please write one in the chat okay only only one jump only one jump I can take either I can take a jump of one or I can take a jump of uh this much two or I can take a jump of three three length or I can take a before any one of them only I can take only one of them I can take okay so if I'm at the ith element now so I can move to uh I if I'm at this ith position right if this is the ith position that I am at right then uh what I can uh do is if if I'm at the ith position then in that case what I can do is I can move to I plus a of I are you getting my point is that clear guys or not please tell me so only one type of jump I can take right only one type of jump I can take here uh so in this case what I will do is uh let's say if I'm at the size position so I is equal to one okay so if you will take a jump of four now so this position will be or two this will be three this will be four this will be five so whatever uh if you are taking a jump of four let's say if you're taking a jump from here to here so you are taking a jump of I plus A5 that is the maximum that you can take so I plus a Phi means I was one one plus a of I is what four so you will reach the index five is that clear so it will tell you the range where you will reach so yes by taking the second M so this is the second name that I have taken because initially from the starting I took this jump and suppose I take this jump so I can see that I will reach the end so total how many jumps I took one more jumps so two jumps please write two in the chat okay so what is the minimum number of jumps that I need to take here in this problem to reach the end only two gems I needed to take correct okay uh is it clear to everyone so I uh was only required to take two jumps here all right now uh let us uh let us see what will happen so I will before that I will also discuss a Brute Force like what can be the brute force method so there is a topic uh like basically now I will tell you one thing okay I'll tell you one thing can I say one thing guys can I say one thing that if I was at like if I was at this element like if I was at uh this element right then from here if I take a jump of one right uh so can I say that only one kind of jump I can take that is I can move from here to here okay so I from here I can only move to here so I can only have I only have the option to move to this particular guy right uh now if you will see suppose if I am at this particular guy right suppose that if I am at this particular guy so can I see that four types of jump are possible for me please write yes in the chat okay can I see that four types of jump are possible for Me Right four types of jumps are possible from here right so if I'm at at if I'm at this F4 right so I can say that either I can from here either I can go to three right so from here either I can take a jump of one or I can take a jump of two so it might be possible that I might have to to take different uh smaller jumps also they might be more better for me or I can go to Six from here okay or what I can do is from here I can go to seven okay are you getting my point is this clear sir I'm not getting how four jumps basically now I am saying like basically if you are having this value as four no suppose from here if you uh kalyani what is happening suppose from here if you reach from here to here then if the value is 4 now so from here you can maximum you can take a jump of four maximum jump that you can take is four but see from here if this is the case so either you can if this value is 4 so you can take any jump between one to four okay you can take a jump of one you can take a jump of two three four okay this is what the pro actual idea is if you are at this ith position so what like you can take a jump of I plus I plus one you can take a jump of I plus two or you can take an i plus three any of one jumps right or you can take a jump of I plus a of I so basically you can neither take a jump to and reach here or you can reach here or you can reach here or you can reach here any one of them you can choose only one of them is this clear kalyani now you can take only one of those jumps only one of those will be possible for you is that clear only one of the only one okay so either you can move from here to here or you can move from here to here or you can move from here to here or you can move from here to here so any one of them only from four from that place okay yeah so now after this so this this is what will happen right so from four either I can go to three two six and seven so please write plus one if you are clear till now right is everyone clear with the graph thing yes please write yes in the chat so like till now I I like either I can reach to three two six and seven is that clear right is it clear guys still now please write yes in the chat and hit the like button as well if you're clear okay give me a plus one and if you're clear till now all right yeah now suppose that suppose suppose that if I had reached at this point right suppose that from here I had taken a jump here okay then what could have been done I could have uh from here if I had reached three so then from three what I could have done is I could have taken a jump of one so I would have reached two if I would have taken a jump like this right if I would have reached from four if I would have gone to three then I would have reached a taken a jump off two if I would have gone to this guy then I would have taken a jump of six I'm sorry I would have gone to six or if I would have taken a jump of three then I would have reached 7. okay so I would have reached this end uh die here is that clear guys is this diagram clear if I would have been if I'm from 4 if I would have gone to three uh okay from this guy if I would have taken a jump of one and I I would have gone to the next guy that is three so from there I could have taken a jump of one two or three any of these three okay maximum three no no maximum three jumps note only one jump either of the jump I have to take okay so suppose that from three now uh suppose that from three if I would have taken a jump uh sorry so suppose that something I would have taken a jump to two now from two either I can go here or I can go here so from two either I can go to six okay or I can go to seven you can see here okay or suppose that if if from three I had gone to six okay if from three I had gone to six so from six either I can take a jump of one or I can take a jump of two three four five six or three so out of bound I can go so from six I can say that I can go to seven also that is the point okay are you getting my point so from six here also you can say that I can go to seven uh and from two you already know that I can go to six I can go to seven here right and from six you can go to seven so I'm just completing this part from six you know that I can go to seven right so you will see here can I say this looks like a graph please write yes in the chat can I say that this looks like a directed graph kind of thing this looks like a graph this whole thing right so we have to find the shortest shortest part uh shortest part to reach the destination guide to reach this last guy right so in this case you can see that when when is what is the shortest number of jumps so if I'll see here if I iterate from here to here and then here right so this is the first cell that I will take first jump and this is the second gem that I will take and I'll reach the ending so this is the fastest fastest that I will reach so basically now in the graph if I try to find the shortest path to the shortest path if I'll apply like I can apply the BFS algorithm and BFS uh breadth first search algorithm if if this was a if you have studied graphs then you can use the graphs approach and then you can uh with the help of graphs you will be able to find that by using two jumps you will be able to reach it is that clear to everyone guys please write yes are you getting an idea at least that uh if if you know the graph suppose you knew graph then you would have applied the BFS algorithm if you know graphs if you if you will study graphs then you will already know BFS okay maybe you might have not studied the graph right now but if you will know graphs then you will very easily know how to move from here to here so in graph you would have taken one step here and the Second Step here and first jump in and the second jump here so then you would have uh got the idea that okay uh like in the graph you would have taken jump from here to here and here to it so the graph would have easily told you using the BFS approach okay but you might not be knowing graphs or you might be knowing graphs that is fine but please give me a plus one so method one is that I could have gone with the graph approach right please write yes in the chat okay so I would have I could have gone up with a graph approach right graph approach okay please give me a plus one if you are clear please write yes in the chart if you are clear please write CLR in the chart if you're clear and please hit the like button if you are clear right hit the like button if you have later along then I will move to the second approach which is the better and the basic approach okay is this clear plus one in the chat guys everybody please write plus one and hit the like button if you haven't already guys let's see if we can reach 175 or 180 likes till the till the end or not 175 likes can we reach 175 180 likes all right thanks a lot isn't graph approach your Brute Force yes it is a Brute Force kind of approach but uh still uh I am just see my job is uh what is the time complexity so time complexity will be the time complexity of the BFS and the BFS technology is order of V plus e so if you will learn about BFS then you will know it okay so it will be V plus C so it will be kind of linear only but it will be order of V plus C so but we can do it better than this like we can do it in order of n Only it will be V plus e because V is the number of vertices that will have any is the number of edges so in the worst case it will be order of V plus e but uh for now we can do it in a like it will be linear only but uh yeah it is a like storing a graph will be uh that thing for this approach what is the tangolicity as I said it will be uh order of V plus e because of BFS and uh you will take space also because you will be generating this graph as well okay have you learned something like is your mind open or not the main thing is that because of this today's session is your mind open or not right because I told you many approach is how to tell these things to an interviewer uh how to think about it how to uh challenge your brain and everything right so did your mind got opened I hope that is the case with all of you right today that is the main motivation right for this boot camp all right so please hit the like button if you are new now uh what I will do is so this method one is clear right now there can be more approaches but let's move to the uh like basic one so what I can do is uh if let's say if I have been given this particular array so if I've been given one port just a second suppose that I have been given what one four then I have been given three then I have been given two then I have been given six and I have been given seven okay uh if do you help placements uh in live course uh currently I am not taking any live course I am only taking the CP course at gfg as of now I think Siddharth takes a life course but I am not taking it I think okay just a second and uh what I will do is increase this yeah so if also if you cannot reach another then you will write -1 if you cannot reach the end then you will write minus one okay so yeah what we will do is now we will keep a variable let's say and we will initially keep the variable let's say as jump okay uh total that will count the total number of jumps we will keep a variable that is going to keep a track of the total number of jumps and initially it is going to be nothing but 0 here okay initially I'll keep the number of jumps as zero and I will also keep a track of the current position okay current current position that I am at all right so initially I will be at 0 before starting like or you can say initially I'll start the current with zero okay then what I will uh do is uh after that I will say that what is the farthest that I can reach okay what is the longest jump that I can take okay what is the longest what is the long uh longest place that I can reach okay so initially I will keep this as 0 as well okay initially I'll keep this as zero didn't understood the question have you joined in between because you did not understood the question basically it is saying the minimum number of jumps that you need to take in order to reach the position so from here if you take a jump of one then from here you can take a jump of either one or a jump of two or whether you can take a jump of this or this or this or this so you can see here if you take a jump of four right so that like if you if you take this long jump then you will reach here so basically total number of jumps is nothing but two here is this clear Aditya are you getting this point now Aditya right you have to do what you have to move from here to here and then from here to here you can move right so basically two jumps you have if you take then this test case will be solved right so initially I am going to mark my current with zero and I'm going to uh say that longest longest is what like if if I will be here right if I am here so I will store now that what is the longest that I can go to so the longest that I can go to is this particular place so I will keep a track of the longest also okay that is that is what I mean when I when I say that I will keep a track of the longest okay guys all right very good now what I will do is I will start off the iteration okay so let us see how I'll start off with the iteration okay this will be I is equal to 0 okay and uh when I am at this particular guy so I will check like I will first of all try and check my longest so can you tell me my longest let's see uh I will try and check so currently this is the ith index so from here can I say that I plus a of I is the is the longest that I can take from here from this position I plus a of I is the jump that I can take agree with me everyone what from here where I can go I can go maximum I plus a final agree if I was here at I is equal to 1 so I can go I plus a of I plus 4 1 plus 4 right so the longest that you can go to any place is I plus a of I so you'll always update your longest uh you will always see whether the longest is uh maximum or this particular thing is maximum I plus a of I okay so is the long like what is the value of I plus a of i 0 plus 1 so it is 1 is 1 greater than uh is one greater than zero yes so what will happen one is going to get updated here right one is going to get updated here okay so I can I will say that okay the longest that I can go to is this particular index one will tell me the longest index that I can reach okay the the uh the longest index that I can reach the basically the farthest that I can reach let me write this as for this that will be better uh maybe for this Index right for this Index this will be the farthest index that I can read just a second I will do this so this is the farthest index f a r d h e s t for this index okay that I can reach so from here I will go to this particular place right so what will happen uh right here is that from here when I will move so that will be fine now after that I will check so what like after that I will check after this point I will check my uh I will check with my current position guys so tell me is the current uh like is the is the current position equal to the I or not what do you think tell me about the current and the I value is the current position equal to I is the current position equal to I or not please tell me yes or no current is equal to I current is 0 and I is also zero so that this means that I am still staying here and I need to move right so if the if it happens right so I'll keep a track of the farthest so far for this is equal to maximum of the farthest comma I plus a of I okay I will do this thing first of all and after this thing is done uh just a second let me move it here somewhat and what I'm trying to say here is that basically what I'm trying to say here is that uh for this is equal to maximum of farthest okay comma I plus a of I right this is what I am going to keep a track of and after that I will check if it happens that the current is equal equal to the I value just a second so if the current is equal equal to the I value then what I will do here is uh if the current equals I then I will say that I will increase the jump because I am jumping okay if the current and the I are same then you can see that I am jumping so I will jump here didn't get the question what question you did not get have you joined just now I I will I will explain it like you didn't get the question or the approach there are two different things what you have not understood till here guys you can hit the like button if you if you ever if you are able to understand till now then you can make sure to hit the like button as well okay uh what which part you did not get can we reach 175 like guys okay so yeah current didn't get which part pratik you can tell me I'm waiting for you otherwise I have to move forward okay so from here to here I will move to this particular place right so in that case I will say that uh okay if the current and I are same so I'm just asking you initially the current was 0 and the I is also zero so if the current and I are same this means that you need to take a jump okay see current is here and current and I are the same so this will mean that you need to take a jump okay when the current and I are at the same position then it will indicate that you need to take a jump that is the only thing that I am saying here okay so in that case current uh like currently the maximum that I can go is this particular index C So currently uh I will be here only so current and I are same so in that case uh I will say that okay uh the current will move to this one like uh in that case what will happen the current will move to the farthest so so see from here where is the farthest place that I can go for this is this one so I will move my current here as well okay that is what I will do after this I am at this particular place at I is equal to 1 and from uh when I am at this particular place now so I have jumped taken a jump of one so the number of jumps is one now if I am here then from here what is the farthest jump like see from here tell me if I will take a jump of four okay if I'm at this I and if I take a jumper 4 then I will reach this index so I'll reach I is equal to 5 because I plus a of I is going to be what uh if you will see so I plus a Phi that is nothing but uh one plus uh what 1 plus AFI is going to be 4 so 1 plus 4 is going to be nothing but 5 right so in that case I will say that now uh between one and five the maximum that I can reach is five okay so now in this case what I will what I will do is I will uh since I have moved here right so uh if uh this was equal to I okay and now again I is equal to this thing yeah now again what is happening is uh again you can say that I is equal to uh this thing right now you will say say that okay again I is equal to like C now the current is here and I value is here so again current and I are at the same position okay so what I will say is that since the current and I are at the same position so the I will say that again I need to take a jump so the number of jumps will be two so now from here I will take the far I will think that okay hypothetically I am taking the highest jump so in that case I will reach here okay because now the far value will get updated here no now the farthest is this particular place so I will place my current here okay and then I will be at this particular ith place right so in that case it will tell me that okay the farthest is here only right then when I'll be at this guy so it will again tell me how this is here and when I'll be at this guy so it will again tell me the farthest is here so at no place when I'm when I'm moving here now so I is here I is here I is here so current is not equal to I okay then so I will just move till here because I have to see whether I can reach the last place or not so you will be able to observe that uh when you will see the so when I will be here so far this will be somewhere here okay 5 will be somewhere right because from here I can take a jump off this much so this means that if I can if I can move at this much place so basically I I have reached the end so how many jumps did I take one jump from here to here and then another jump from here so one Jam I took at this place and another jump I took at this place so when I was currently here then I took a jump okay then I moved here so I was here and current was here then after that I moved here and the current also moved there then also I took a jump right so that is why when I and current are same then I am taking a jump and after that I am moving the current to the farthest jump that I can take right so then the current moves here so then after that at no place I N current are same so I never need to take any other jump right are you getting my point so this basically this indicates that I only need to take two jumps that is how the code will work so is the idea clear or not guys please tell me uh is the idea clear to everyone if yes then please hit the like button and tell me guys is the idea clear to all of you or not let me know what about others current is equal to maximum yeah maximum possible that we can reach here okay let's talk about uh another case guys okay let's talk about another case so is this much part clear please write yes in the chat plus one in the chat at least till now if you are clear right so what I am saying here is uh basically something of this kind what is what shall I say for this time initially initializing to zero I'm initializing my current to zero and then what I'm doing is uh what am I doing jumps initially I'm marking as zero okay then what we are doing is a of 0 is 3 but we took jump to index a of zero was three no it is a of 0 is 1 only e of 0 is not three here why are you saying a of zero is three a of the Z the very first element is one only why are you saying it as three yeah if it is if it was three then the farthest that we can go is three yeah then in that case the further setting can go is three correct sir if current is less equal to Maps then we only jump right uh current is less than equal to Max no no we you keep on taking the jumps I will tell you more about it just give me some more time when we'll discuss a little bit more of test cases then you will understand it okay then what I am going to do is I'm going to run a loop I will not go till the very end okay I will not go to the last I will be less equal to n minus 2 because I I will see whether I can reach the last index or not and then I will do an i plus plus okay so what I will see is I will say that for this is equal to maximum of whatever the farthest is containing comma uh what should I say maximum whatever the file this is containing comma uh I plus a of I okay that is the jump that you can take and if it happens that I is equal equal to the current as I said as I showed you if I and current are same then it is compulsory for you to take a jump then you will say that you will take a jump plus plus okay and if you are taking a jump then you will say that okay current will move to the uh if you are taking that particular jump you know then what will happen guys current will move to the far this point right that you could have gone to so you'll move to that point and in the other scenario what we will uh try to do is uh there is one more thing that uh we have to write here so in this case if this is the situation right so what I will do is uh after this I I need to write one more thing but I'll write it see uh it might happen like let's suppose that if you have a test case of this line okay suppose that you have one okay then you have something like zero okay then you have three four five okay let's say you have this particular kind of a example then what is going to happen here let us try and understand okay guys can we try and understand this one so suppose that if you are initially here okay so the number of jumps initially will be what uh zero then your current will be initially at zero okay and your for this that you can reach will also be at zero so initially your current is here okay your I starts from here so now what is the farthest that you can reach first of all you will take out the further so far this will be I plus a of I so for this that you can go will be what farthest will become nothing but one okay please write yes in the chat so far this will become one right now is the current now tell me is the current equal to I yes or no please tell me is the current and the I same yes or no guys please tell me is the current and I same yes so this means you need to take a jump right so you will take the jump the moment you take the jump so so jump plus plus you will do the moment you take the jump so current will move to the farthest point so so the farthest point is this point right let me write this so this is the farthest point so current will move where current will move here okay then after that I will also get updated so now after that I will move here and now from here like you will compare so one uh right one plus zero because this element is zero so from here uh one plus zero so far this will be updated as one only right after that I see that okay current Uh current and I are the same okay uh in this case you can see that the current and the I are the same right so then in that case uh if the current and I are the same then I will say that uh let's say again I will take the jump so I will say that okay jumps is equal to two then what will happen my I will proceed further but uh but uh my I will proceed further so I will move here but currently I'll still be here because I will be at the farthest point that I can reach and the farthest is still one because the for this will be one maximum of one comma zero plus uh one plus zero so that is one so maximum I can reach is still further set I can reach current will be at one only and I is equal to two so whenever I crosses okay when if if it happens that I is greater than current then in the loop you will return minus one are you getting this way is this clear guys are you getting this point if the I a is greater than uh the current then you will return minus 1 is that clear or not yes please tell me when I is greater than current then you will return -1 please update current as well uh yeah I will update the current as one sorry okay others other people are also clear if it like see I moves here so I will check whether I can reach till here or not so current says uh for this that I can reaches here so current is also standing here and I cannot I cannot do anything here okay is it clear to everyone guys please tell me so that is what we are uh doing here right okay now please uh hit the like button and give me a plus one if you are clear till now right please hit the like button and give me a plus one or write clear in the chat if you have understood till now okay have you understood till now yes or no guys please tell me so what I am going to do here is the uh I will discuss the last test case with you as well after the after the like I will discuss this Safeway so don't worry okay I'll try to discuss this case but let me just write the code also and this problem has been asked in a lot of companies okay uh Flipkart Amazon Microsoft housing.com Walmart Adobe Google a lot of companies have asked this one so what I will do is let's say in for this initial Market as zero and I will Mark the current as 0 as well and then I will initially Mark the number of jumps as 0 that I have taken okay then what I will do is I'll run a for Loop so I will say that for end I starts from 0 and I will go till the second last try because I don't want to go to the I will I have to check whether I can reach the last or not so that is why I'll not go through the last indexes that clear to everyone okay now what I will do is I'll say that uh for this that I can go is equal to nothing but maximum of the whatever the farthest value is storing comma I plus AFI that is the term that I can take maximum that I can take from the ielt okay because because understand one thing now what I'm trying to tell you is that if this guy was one suppose then suppose this guy was what 10 okay uh and suppose this guy was something like five okay so so suppose that what you do is from here you uh go here right guys suppose suppose that from here you go go at this place and from where you take a jump right so you will take you will be able to take a jump of 10 from here are you getting my point right you take a maximum jump that you can take is of 10 right maximum uh that you can skip is 10 right okay but suppose that what you do is you move from here to here and then you move to here from here to this guy and then you are able to reach only till here right so this is what the fire is destroying right are you getting my point far is it storing that what is the farthest so I am also checking this guy this will be I plus a of I right uh if if the I is standing here right if I is standing here so I plus a of I will be what I plus a of I will be this guy so I am comparing so I am always comparing what is the farthest that I can reach please write plus one are you all clear with this particular diagram or not guys uh please tell me the chat ad please hit the like button if you haven't already done this okay can we reach 200 likes before the end of the session okay so that is what the furthest story is that clear far is the maximum reachable index yes far is the maximum reachable Index right correct far is the maximum reachable index maximum reachable index correct maximum reachable index correct is that clear so from here the maximum reachable index will be suppose this much and from here I'm checking so I'm checking I'm going to only through this much so I'll always keep a track like I'll use always I'll always show this first and from other places also I'll try to see and suppose if I if I see that okay from there I'm jumping jumping if I come here again so this means from jumping from like see what does what does it mean when uh when the uh current and I will be like see what does it mean when the current and I become the same so basically what I uh will do is now for this is here so current will reach here and suppose I keep on checking for the rest of the elements okay I keep on checking for the rest of the elements but even after that if I reach here so this means that from here the fastest that I can reach is here so only taking one jump is optimal so I will say that okay if this is uh if that is the case so then I will do a jump plus plus okay whenever I and current becomes the same at this particular point so that is why I'm doing it right guys so yeah this is what I will do and after this what will I do after the furthest I am going to check if the current is equal equal to I then I will say that okay I need to do a jump so I will increase the number of jumps and then what I will do is I'll say that now current uh I will say that current is equal to far okay so I will make the current state at the farther zone right because if you want to take the least number of steps so you will tell the uh this uh you will tell the current that okay sit here and suppose suppose and you will also keep on iterating so suppose you are at this index and this index tell you tells you that okay I will help you to reach here somewhere so then you will store this as the furthest and then after that you'll update the current at this place in that case as you get in my point so that is what I am trying to say here so yeah this is what we will do if it happens that I becomes greater than the current so this means it is not reachable and I should directly return -1 are you getting this point guys if I becomes greater than the current at any point of time then I should be returning a minus one like uh is this uh is this part clear or not but what I'm thinking is maybe let me do one thing maybe we can do afterwards also so what I what we can do is if it happens that that suppose the current at the very end if the current is less than n minus one so if I'm not able to reach the last position okay then I uh last index if I'm not if if the current is if after skipping is skipping is skipping skipping if the current is showing the last position that I was at and if the last position is less than the last index okay in that case I will return like if it is less than n n minus 1 so if it is less than the this thing then I will say that I was not able to reach otherwise I will say that I can reach and I will return the number of jumps here so are you getting this idea guys or not you can check it in the loop also but uh taking it here is also fine I think just a second uh is this much part clear current is confusing for me sorry uh current see basically what will happen first of all you keep a track of the farthest that you can go to so far this suppose you can go till here only then after that if you are taking the jump so when you take the when I and Lexi uh when your I is here and your current is also here uh okay so I and current are same then you will take then you will say that okay current will sit here because if you are here so you will take this one jump that is what I am trying to say so current will move from here to here for this has to always keep a track of the maximum Zoom okay uh all right I'm still not able to do it what is the issue let me name this array as a only is this clear to everyone or not guys please tell me basically this is a logic based question yeah it works on the samples let me try and submit this code as well okay it does work so up till now is this problem clear to you guys or not please tell me at least till now if you are clear please hit the like button and tell me if you are clear with it or not guys what is the purpose of current can I when we can check for yeah you can check far also but for better understanding if you are in an interview so you have to also tell about a little bit about the processes also now that is why if you are clear till now guys so you can see what will be the time complexity guys you can see that the time complexity will be nothing but order of n because I'm just running a loop okay so let me just discuss about the time complexity so the tying complexity is going to be what it is going to be nothing but order of n okay and the space complexity is going to be what it is going to be order of one because we are using no extra space no extra space right in this method quickly take a recap yes yes I can I can do a recap for the next test case please uh but before that guys uh please uh if you are new so please hit the like button okay yeah and you can share this uh with your friends as well if you are coding in groups and please give me a plus one in the chat as well and hit the like button also right can we reach 185 or 190 likes before we end somewhere like somewhere like that amount okay I went to a recap no worries I will do a recap on this part on the on this particular test case Okay first first test okay let me write copy these elements let's say the array looks like what first of all you have one here then you have three here then you have five here okay then you have eight here so M value is 11 that is then you have nine here let me know if I write anything in the course deceptively save this yeah code is simple we can shift to 9 11. uh I don't have a say on the timings okay seven seven six but did I like yesterday whatever level was left so did I increase that or not please write plus one do you feel like yesterday Siddharth left on a very high level so did I uh did I was I able to satisfy all of you or not guys plus one if you think so then eight is there then nine is there two is there six is there seven is this six is there eight is there and nine is there all right so so yes this much point is there all right now what I will do here is uh what I will do here is in this case uh let's see so initially I will be at zero okay and the current will be zero and the furthest will also be zero and the number of jump will also be zero okay then uh the current will be here initially right so here you can see that what is the farthest so far this is let's say one right so since the after the updating the furthest just satisfied okay it's my first day but everything is awesome thanks a lot kalyani so yeah how did you get to know about this buy a gfg article or some friend shared it with you guys okay I is equal to zero and I and current are the same after that okay so current will move here till the farthest till the farthest I can go so I have to take a jump so current will move here okay so uh like this is where the farthest is and this is where the current is also standing okay so this will be the farthest and this is where the current will stand at all right uh after that so jump the number of jumps will increase by one so I have taken a jump of one gfg article okay very good LinkedIn so okay uh if you like this now then what you can do is you can take a screenshot of this and you can uh mention it on LinkedIn as well okay guys you can take a screenshot of this you can tag Sandeep sir and me just give me a second I'll tell you what you can do okay uh if you like this session then you can let's say you can take a screenshot of this thing first of all take a SS when once you take the SS no please write SS in the chat okay once you are able to take the screenshot so just write SS in the chat Instagram okay yeah just quickly take the SS of this one or maybe this one whatever you feel like okay or you can take access of this screen or you can take access of this screen okay now once you have taken it uh so what you can do is you can tag me and some leave sir okay on the LinkedIn and you can tag like you can write gfg uh 21 uh days like basically you can say that we have joined the gfg 21 days boot camp uh okay uh and you attended this session so you can tag me here is my LinkedIn profile uh so my name is Yash divedi you can tag me and as well as Sandeep sir at the same time okay if you will do it you can give me a plus one and let's come back to this question now it's not compulsory but it totally depends on your choice right so that it can reach more people that's it yeah so now what will happen here is uh we have the farthest uh we have the farthest standing at uh this particular uh okay just excuse me second I think I need to increase it yeah so uh now the farthest is here and the current is here okay so in that case uh yeah current will move here then father this is also here so I will move so I will come here okay so I will be at one then I can say that uh now what is the farthest that I can go to so I Plus One will be 4 so this will be one two three and four so the farthest will now move here okay so the for this will get updated to what uh you can say it will get updated to this thing that is nothing but uh this is index four no one two three Fourier so it will be updated to four okay and I value is one okay so again uh I value is one I and current are the same so if I and current are the same so again I need to take a jump please write yes in the chat guys so you will start understanding this problem just tell me if this much point is clear again you need to take a jump can you save the previous solution uh I have shared it already I think long back but I will try to share it don't worry uh just give me a second yeah previous solution I'm trying to [Music] share it here okay yeah so what we will do here is you can see that uh the farthest uh is here right now uh now the current uh now the current and this is are the same so jump the number of jumps will get updated to two because the current and I were same here also so jumps will get updated to two and the current will move at the farthest so current will also move here okay then after that I will move my eye here okay so my eye moves here now uh suppose that if I am at this place right so uh if I am at this I is equal to 2 then how much far I can go I can go to seven right so I can go to seven okay from to like uh pratik will also understand so pratik please be very attentive here okay because now the farthest and current will not be the same okay so I is at 2 and the farthest that I can go is seven right please write seven in the chat guys are you waiting my point because for this is starting at Fourth now for this will uh for this that I can go is seven so for this will get updated to seven so this will be five six this is where the furthest will go okay index seven okay then I will go here so this will be I is equal to 3 and the fathers that I can go from here is 11. okay so from here the farthest that I can go is 11 right so 8 9 10 8 9 10 11 so my father's will go here okay 11 something like this okay so this is a hypothetical place you can say okay uh if I am here now after that suppose that if I am here okay then what I can do is uh I will be equal to what after this I will be equal to 4 here okay so up till now I have taken only two uh two jumps you can understand from here to here one name I have taken and supposingly if I'm if I have taken a jump from here to here right so in that case from here to here if I have taken so this will be eleven so now the farthest will move again so far this was 11 now it will get updated to 13. so current is very important for us right that is why it is important because for this is keeping a track of the farthest position right so uh this was index 11 suppose hypothetically this is 13 Index right okay for this will be here now since the I and the current become the same right here iron current are becoming the same so I I will say that yes I need to take a jump I need to take a jump because the current and uh for this have become the same okay so then because see if the farthest became here then I never came at the end but so I is going till n minus 2 only so if till n minus two if I'm stopping anywhere so that means I need to take a jump so I'm only checking till n minus 2 with Index right I'm not checking till the end so now here if I and current are same so this means that I need to take this jump and when I take this jump so basically I'll reach here so you will be able to understand that again when I'll move forward now so far this will keep on moving and I don't need to take any job right because uh when uh when I will take the jamuna so current will actually move here and uh you will see that when you will move when you will move through these indexes right all these indexes then the farthest will move somewhere here okay and your I will move here I will move here till here you will move so you can see that uh like and your current is here okay you can see that after this your current is still standing here and your eye is moving till here so then after that I N current are never the same and you can see that the number of jumps that I have taken is what three so the jumps gets updated as three that is why the current has its own importance right right is that clear guys uh so the farthest is here and current is here so this means that I don't need to take a jump after that so I hope that the dryness grinder pretty much length and how we are only taking three jumps indirectly you can see this right because with the help of physiology I would be able to reach them basically directly I'll go from here to here only as the last guy but you can assume that yes if I can go till the very far outside the area so basically I can go at the end right is that clear to everyone please write plus one clear in the chat if everyone is here till now I hope that this makes a lot of sense plus one plus three because the number of jumps that I have taken for this this case is three so plus three in the chart if everyone is clear till now and you can let me know if you are clear with it or not clear with it all right guys just let me know kalyani is saying clear so can if you are clear guys please tell me if you are clear uh so you can understand that the time complexity since we are running a loop till the second last index so time go to series order of n you are not taking any extra space so the space complexity is order of one and the companies that have asked this particular question are Google Microsoft okay Amazon and Ado and many others are there I'm just writing only some of them Hadoop so these are the companies that have asked this particular question right so the time complexity is order offense phase complexity is order of one and if you enjoyed this session so please uh tell me uh by hitting the like button okay please hit the like button right plus one in the chat or new in the chat and also share this video with your friends if or or you can share this on LinkedIn as well right so you can you can take a photo of this right and if you want you can take a screenshot of this you if you're taking the SS you can let me know if you are taking the SS then you can tag me and Sandeep sir I have shared the LinkedIn ID above if you want I can share it again just a second so yeah if you want you can tag me and Sandeep sir and you can tell that you enjoyed the session that you attended here okay I'm just sharing it again with you here if you enjoyed if you genuinely like the effort then only you should do it is not compulsory but if you are going to take a screenshot you can write SS in the chat if you will be posting so I will try to see it okay uh right so if you did understood it you can take a screenshot of this screen or you can take a screenshot of uh this one also right if you are clear with it okay guys I hope that you did enjoyed it really okay you have taken the SS you can take this as this is screen SS also and you can paste it uh on LinkedIn right like you can basically write a post there if you if you like this session okay bye you can tag there Sandeep sir Sandeep jancer and me okay so uh yeah I'm just telling you so if you like this then yeah you can take a screenshot I'm just waiting for one more second uh either you can take either you can attach this screenshot or if you want then you can attach this particular screenshot okay uh so I hope that you have taken the screenshot I'm giving 30 seconds on this screen and I'll give 30 seconds on the next screen also right and yeah either you can attach this one or this one and what you can do is you can basically uh tag me and I have given my LinkedIn ID okay and you can stack Sandeep jancer also okay you can just search you can write at the rate and then add the rate and Sandeep and I think it will come right when you're writing the post notes then you can write at the rate and Sandeep Jan then it will come okay what about the description post what what is description post so how can you calculate the space and time complexity here because uh we are just running a loop order of n times now we are just running a normal Loop that is why it is order of n just give me a second I learned a lot in LinkedIn yeah in on LinkedIn you can tag me and Sandeep sir okay and post it and you can tag Geeks or Geeks also okay so if you genuinely want to it's not compulsory uh but I hope that you did enjoy and before ending please uh learn two more okay what should I add in the post description you can write that you enjoyed this session you attended this particular session you can attach the screenshot and you can just write that you attended the sessions and you saw these photos and what you learned also the new things that you learned and what you what do you like about it you can just write that very basic thing nothing much we are asking for okay is this clear to everyone okay and if you want you can share the bootcam link or the YouTube video link as well okay you can share this YouTube video link as well in that post okay so yeah this is the uh problem and I hope that I have given the code for it as well yeah so I think I've given the code for this one as well okay so this problem was also really good so uh guys uh please let me know did you enjoyed the overall session I hope that you did like it okay uh I'm sweating but uh you did all of you did enjoy it or not like can you share it with your friends in some water WhatsApp group and somewhere and can we get 200 likes before we end the session uh what do you think try to shift the time eight to nine it's my mess time I can understand you uh hard you must be in Hostel okay n minus two Q because last because Rashmi Singh last Wale we want to reach the last guy so you have to check whether you can reach the last guy or not okay without going to the last without going to the last index last index is n minus two index so without going to the last index can you reach the last index or not that is what the question says so that is why without going to the last index you have to check whether you can reach the last index or not so that is why we have to run one less one index lesser again and others also last is yeah because the indexing is zero based no actually indexing of the arrays uh like what I'll share my screen I'll show you actually the indexing of the array is like what are actually the in in an array the indexing is what zero right one two so the last index will be in n minus one no will it be possible sir uh I don't think uh personally I don't think leadership will be possible because uh the team has decided it is it based on certain data points and how much people are active how much people will be able to join so I personally I don't think so but uh I will uh send this message of yours to them okay but I think it will be very difficult because it sometimes it might reach 12 right plus 30 likes okay can can can we get uh some likes and then yeah we can move forward all right so yeah I hope that you did enjoy the session okay so one thing that I want one last thing that I want from all of you I'll write that as well okay so after this video is over just after see when I will end this video now so what is going to happen is just a second I'll tell you after uh this video will be override so see I have opened this particular video you can I hope that you can kind of roughly see it here although there is a Flash coming yeah you can see it so after this video will be over now when you will refresh the tab right after I will uh stop the video then you will refresh the tab then our live live video will become uh non-life okay then you will uh then you can go to the video then you can go to our video and you can uh write understood okay and you can write plus one enjoyed the session and all those things if you did understood if you did like the session genuinely okay will you do this plus one in the chat and if you learn something new for the very last time if you have not liked the session please like the session make sure to attend tomorrow's session as well okay and please give me a plus one if you enjoyed today's session at least everyone all right so yeah just write new in the chat plus one in the chat uh before ending and good night in the chat as well thanks a lot thanks a lot neeraj okay voting sir voting can be done the other people can tell us like mostly I think they like the ATMs 8 AM 8 PM slot I think that is the reason okay so yeah you can share it with your friends okay make sure to share it with your friends in some groups and after this video is over just after this video is over as I have told you uh just after this video will be stopped then you can refresh your YouTube feed and then you can uh comment on this video okay make sure to comment and share it with your friends in your class groups in your WhatsApp groups make sure to share it and share it on LinkedIn as well I'm not I don't know I don't know about it I'm not sure uh so sir is it okay okay they are saying 8 to 10 is okay fine all right so I hope that you enjoyed thanks a lot guys for joining and after this video is over please please make sure to share it in your uh class groups in your WhatsApp groups in your uh what you can say batch group right in your college groups you can share it and thank you everyone for joining I hope that you enjoyed this and make sure to keep coding keep solving the problem of the day keep uh uh attached keep being attached to Geeks or Geeks and also subscribe the channel geek so Geeks practice for which I gave the intro initially so GMG practice is one regularly so you can just search that on YouTube as well what about a third use three you wish third problem also I've sold first first of all I saw the first then second then third and then the second so I've solved all the three problems what about third third use third years okay uh yeah thanks a lot guys and keep coding good night everyone take care and thanks a lot for being there till the very end bye guys thank you keep coding
Original Description
Welcome to CodeCamp Day 2! In this exciting session, we dive into the world of Data Structures and Algorithms (DSA) Fundamentals and embark on a journey of problem-solving challenges.
During this action-packed day, we will explore the essential concepts and techniques that form the foundation of DSA. Whether you're a beginner eager to learn or an experienced programmer looking to sharpen your skills, this session is perfect for you.
Read this Article-: https://www.geeksforgeeks.org/gfg-codecamp-build-coding-habit-in-just-21-days/?utm_source=youtube&utm_medium=courseteam_main_desc&utm_campaign=CodeCamp_Day2
Problem 1-: https://practice.geeksforgeeks.org/problems/sort-an-array-of-0s-1s-and-2s4231/1?utm_source=youtube&utm_medium=courseteam_main_desc&utm_campaign=CodeCamp_Day2
Problem 2-: https://practice.geeksforgeeks.org/problems/minimum-number-of-jumps-1587115620/1?utm_source=youtube&utm_medium=courseteam_main_desc&utm_campaign=CodeCamp_Day2
Problem 3-: https://practice.geeksforgeeks.org/problems/count-the-subarrays-having-product-less-than-k1708/1?utm_source=youtube&utm_medium=courseteam_main_desc&utm_campaign=CodeCamp_Day2
Explore Premium LIVE and Online Courses :
https://practice.geeksforgeeks.org/courses/?utm_source=youtube&utm_medium=courseteam_main_desc&utm_campaign=CodeCamp_Day2
Follow us for more fun, knowledge and resources -
💬 Twitter- https://twitter.com/geeksforgeeks
🧑💼 LinkedIn- https://www.linkedin.com/company/geeksforgeeks
🗣️ Facebook- https://www.facebook.com/geeksforgeeks.org
📷 Instagram- https://www.instagram.com/geeks_for_geeks/?hl=en
💌 Telegram- https://t.me/s/geeksforgeeks_official
Also, Subscribe if you haven't already! :)
#GeeksforGeeks #DSA #Programming
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from GeeksforGeeks · GeeksforGeeks · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
How I got into Walmart | Shailesh Sharma
GeeksforGeeks
Upgrade yourself In 29 Days | GeeksforGeeks
GeeksforGeeks
Learn AWS Fundamentals For Free
GeeksforGeeks
Conversation With Young Achievers | Meet the winners of Bi-Wizard Coding Contest | GeeksforGeeks
GeeksforGeeks
Meet The Winners Of Bi-Wizard Coding Contests | GeeksforGeeks
GeeksforGeeks
Interview Prep Strategies | PayPal
GeeksforGeeks
OLX Interview Preparation Strategies | Hukam Singh
GeeksforGeeks
Meet Some More Winners Of Bi-Wizard Coding Contests | GeeksforGeeks
GeeksforGeeks
Live Mock DSA
GeeksforGeeks
Microsoft Azure For Absolute Beginners
GeeksforGeeks
Python for Data Science | Data Science Master Bootcamp | Arpit Jain
GeeksforGeeks
Getting Started with Data Analysis | Data Science Master Bootcamp | Ashish Jangra
GeeksforGeeks
How to prepare theory subjects for SDE interviews | Geeks Summer Carnival 2022
GeeksforGeeks
Get Your Tickets To The Geeks Summer Carnival | GeeksforGeeks
GeeksforGeeks
TED Talk Data Analysis Project | Data Science Master Bootcamp | Ashish Jangra
GeeksforGeeks
How I Secured AIR 9 in GATE'22 | Tushar
GeeksforGeeks
Learn Java Backend Development | Geeks Summer Carnival | GeeksforGeeks
GeeksforGeeks
How to Recognize which Data Structure to use in a question | Geeks Summer Carnival | GeeksforGeeks
GeeksforGeeks
Learn Data Structures and Algorithms | GeeksforGeeks
GeeksforGeeks
Interview experience at Flipkart | GeeksforGeeks
GeeksforGeeks
Lets Prepare for GATE'23 the Right Way | Sakshi Singhal | GeekSummerCarnival
GeeksforGeeks
Highest Paying Jobs in 2022 | Ishan Sharma | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Geeks Summer Carnival 2022 | 5th April- 11th April | GeeksforGeeks
GeeksforGeeks
Preparing for SDE interviews | Soham Mukherjee | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Full Stack Development with React & Node | Utkarsh Malik | Geeks Summer Carnival | GeeksforGeeks
GeeksforGeeks
Introduction to Open Source and Roadmap to GSOC 2022 | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Web Scraping in Action | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Getting Hired at BITCS via GfG Job Portal | Get Hired With GeeksforGeeks
GeeksforGeeks
How to build a faster landing Page | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Geeks Summer Carnival | 5th To 11th April, 2022 | GeeksforGeeks
GeeksforGeeks
How to get ideas for Startup | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Journey from Tier 3 to JusPay | GeeksforGeeks
GeeksforGeeks
Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Dispelling Myths and Pre conceptions of Programming Languages
GeeksforGeeks
Must Do System Design Questions
GeeksforGeeks
Understanding Sorting Techniques in an hour | Keerti Purswani | Geeks Summer Carnival
GeeksforGeeks
Get Hired at NEC | Job-A-Thon 8
GeeksforGeeks
Journey from Tier 3 college to Microsoft | GeeksforGeeks
GeeksforGeeks
Get Hired with GeeksforGeeks at SuperK | Job A Thon 8
GeeksforGeeks
GeeksforGeeks: Redesigned
GeeksforGeeks
From Tier 3 to cracking multiple interviews | GeeksforGeeks
GeeksforGeeks
Live Mock DSA
GeeksforGeeks
Youtube Data Analysis | Ashish Jangra | GeeksforGeeks
GeeksforGeeks
DSA Self-Paced Course Preview | Sandeep Jain | GeeksforGeeks
GeeksforGeeks
GATE Live Classes | Prepare for GATE CS 2023 | GeeksforGeeks
GeeksforGeeks
Journey from JIIT to Adobe
GeeksforGeeks
Life Is Unfair Ft. Shonty badmash | LIVE Discord Session | A GeeksforGeeks Exclusive
GeeksforGeeks
Interview Experience at Google | Tech Dose
GeeksforGeeks
Live Mock DSA
GeeksforGeeks
Interview Experience @ Amazon | GeeksforGeeks
GeeksforGeeks
My journey through the tech world from India to US | Vidushi | GeeksforGeeks
GeeksforGeeks
Complete Interview Preparation Course | GeeksforGeeks
GeeksforGeeks
Live Mock DSA
GeeksforGeeks
Getting Hired at FiftyFive Technologies | Job-a-thon 9.0
GeeksforGeeks
GFG Karlo, Ho Jayega | GeeksforGeeks ft. Khaleel Ahmed
GeeksforGeeks
How I got job offers from 2 big companies : Arcesium & Microsoft | GeeksforGeeks
GeeksforGeeks
LINUX for Beginners | GFG x Itversity
GeeksforGeeks
My interview experience at Walmart | GeeksforGeeks
GeeksforGeeks
Get Hired at Speckyfox
GeeksforGeeks
Live Mock DSA
GeeksforGeeks
More on: Algorithm Basics
View skill →Related Reads
📰
📰
📰
📰
Morris Pre Order Traversal
Dev.to · Jaspreet singh
Advanced Stack ApplicationsData Structures and Algorithms Deep‑Dive — Advanced Stack Applications…
Medium · Programming
The Minecraft anvil is a tree-cost optimization problem in disguise
Dev.to · Mark
KMP Algorithm (Knuth-Morris-Pratt): The Smart Way to Perform String Matching in O(N)
Dev.to · Jaspreet singh
🎓
Tutor Explanation
DeepCamp AI