[00:00:02] Going through the, just start going through some pseudo-codes, not writing, jumping into the code directly. [00:00:11] Okay. You just start with the pseudo-code. What do I mean by pseudo-code, if you can understand? Why do you delete? [00:00:24] Yeah. [00:00:27] I'll go to the playground. Morning, so please. Just let me say I'm asking. Okay. Spend me some time. Okay. [00:00:40] okay yeah let me say my spend first and let me share you the today's link also okay [00:01:15] uh this is your link go through the link okay if you haven't created your account please create [00:01:40] one account okay register with the today's assignment okay i don't know why these guys [00:01:47] not running from external so today's class is about uh um you can say about the stack okay [00:02:09] uh not really stack but the array also okay so this kind of way you can say question tricky [00:02:16] questions okay uh yeah so we have to the first question is like okay so what we will do today [00:02:26] okay we'll do this question okay so this is the first question i'll give you the brute force answer [00:02:34] okay and another one i'll give you the optimal answer okay now i'll i'll go through this question [00:02:43] okay i'll give you the solution of a brute force answer okay and you have to find out the optimal [00:02:49] answer uh in that you have to solve it got it okay so this is a simple question only there is no any [00:03:01] there is no any like rockets and things okay someone is submitted also okay [00:03:15] oh how's the day going guys like good why eight links because people are asking like [00:03:25] many times okay that's why i send it eight times you want ten times i can send you one two more [00:03:30] times okay so let me go to this link by this not scrolling okay what's the last one okay [00:04:05] so did you go through the question what the question is saying and what you need to find [00:04:12] made it sit full screen okay yeah no i'm going forward i can't i cannot able to join [00:04:27] more guys okay you guys join in from this thing okay so yeah let's go through the question what [00:04:40] this question is saying hi lakshmi harika but i'll take the question in the middle of the station [00:04:48] okay please keep your uh hand raised okay uh but i'll take yeah so okay so problem statement is [00:05:01] you are given in integer okay integer of array n of size n for every element in the array [00:05:09] find the first greater element to its right side okay correct we'll take one example and we'll see [00:05:17] what this question is saying okay and if there is no greater element to the right [00:05:23] you will return minus one okay and your solution should be uh use a stack to efficiently find the [00:05:30] answer okay we'll use stack but in the optimal way first we will go through the brute force [00:05:35] brute force way okay like how our mind is selling to the question like let's say [00:05:42] let's say you first see the question how your mind is telling what should be the approach to [00:05:50] this problem okay we'll go through first that and then we'll go through the optimal okay what would [00:05:56] be the our worst case and how should we find the optimal for that okay so the input format will be [00:06:03] okay the first line uh says as it is like a contains uh it is an the size of the array [00:06:10] okay the second line contains n space separated integers representing the array okay the [00:06:15] constant is given okay perfect and then the output format will be print and separated integers the [00:06:26] ith value is output should be first element to the right of a of i that is greater than a of [00:06:36] i okay uh we'll copy we'll copy in this only okay so first uh we given one uh like a six [00:06:49] six six elements are there okay inputted and some output is we'll understand the [00:06:55] problem first okay and then see okay okay so first is telling that we [00:07:07] third element okay so i copied this okay so we need to look at only its right side okay [00:07:19] as the question said correct so if you will look into the right side what what's the right side of [00:07:27] four five two eight uh five two ten eight seven correct so the first greater uh then four is five [00:07:38] right so i'll write like this okay so this is the first greater okay so this is the first greater [00:07:50] correct now we'll take now we'll take the five how will you take five okay who is the right [00:07:58] side of it okay uh so we'll list out the all the elements also okay so let's say let's say you are [00:08:07] looking at uh right side of four then what are the elements five two ten eight seven correct [00:08:16] who is the next uh who is the first greater element is five correct we found out okay so now [00:08:22] take the five okay two ten sorry eight is ten minute seven okay now two is not greater than five [00:08:34] right who is not greater than five correct who is the next greater than ten okay so five [00:08:50] then 10 will come correct now we will repeat for this every element okay so like uh then [00:09:01] for what element is there two okay so who is the next greater okay is the next created [00:09:11] 10 only okay now 8 okay sorry 10 there is no greater element right so if there is no [00:09:20] greater element then we will put minus one okay now comes to the eight okay there is greater [00:09:28] element to the right side no we'll put minus one okay now seven always minus one because we don't [00:09:35] have any right side element correct now there is a simple approach we can find out okay for every [00:09:42] element we have to start looking for the next positions until we find a greater element correct [00:09:48] so uh why i said like that because in the case of a 5 okay in the case of a 5 we did not find out [00:09:57] like a next greater element that's why we look for the next greater element okay which is 10 [00:10:02] okay so until that we have to find out okay who is the next greater element and list down it okay [00:10:08] so if you will see like that if you will list down this okay what is the problem statement [00:10:13] now if you will list down it then 5 then 10 again 10 okay because uh 2 is there so uh 2 is there okay [00:10:27] then uh or 2 because 10 is greater element okay in case of a 10 there is no greater element that's [00:10:37] a minus 1 in the case of a 8 there is no greater element to the right side so that's why minus 1 [00:10:42] okay this one in this case of a seven there is always a minus one okay why there is no any right [00:10:49] side element okay in the case of a you can say uh this example also you can take and you can find [00:10:55] out this okay so what should be the uh like a answer okay so as a bhavna you can like ask okay [00:11:03] so how to write the code okay we'll first go through the pseudo code first we will not jump [00:11:09] into the python port okay we'll first jump into the simple solution okay how how should we solve [00:11:16] it okay so we are going through this list okay so if we are going through this list okay then for [00:11:23] sure that will will like a uh apply the for loop okay what came what the bare minimum requires the [00:11:31] for loop okay because we are going through this list right so how i will write [00:11:36] for i equals to 0 to n minus 1 okay something like that i'll write okay then i'll take one [00:11:46] answer okay which will compare which will like a simple storing is minus one okay because as we [00:11:55] know that like in the last element we are always getting the minus one okay so that's why i'm [00:12:01] keeping by default as a minus one to the answer okay i'm taking one variable okay the minus one [00:12:07] okay and then and then what i will do i will check okay for the checking purpose i'll take [00:12:17] another variable okay i'll go through it okay i'll take another variable which is i plus one [00:12:24] okay this is the simple approach i'm telling okay so first element we are comparing with the second [00:12:29] element that's why we will take i plus one okay we are starting from i plus one okay that's why [00:12:35] which will go up to n minus one okay i'll keep column over here okay okay why these guys are [00:12:46] joining from external i don't know two to five guys okay i admitted them all okay [00:12:59] Now, I will go through the question. [00:13:03] So, I am taking another variable, another forlook for the comparison. [00:13:10] I am taking from the i plus 1. [00:13:12] See, this one I am taking from the 0 because index is always starting from the 0 position. [00:13:18] I am taking from i plus 1 because we have to compare with the second element, which [00:13:23] is right element. [00:13:24] That's why I am taking i plus 1. [00:13:26] Now we will compare. [00:13:27] How we will compare? [00:13:29] if a of j a of j means this is the if the second element is greater than okay this is greater than [00:13:41] the first element the answer answer will be a of j okay correct because if if that is a greater [00:13:59] then we are taking answer is a j then sorry then we will break this okay because we got an answer [00:14:09] we have to break out of the loop that's why i play the break statement then what i will do [00:14:14] i will print the answer immediately okay i'll print the answer correct answer yeah sorry guys [00:14:31] i was attending another call also okay that's why i'm bit of a diverted okay oh okay so there's the [00:14:44] break uh that's why i put okay now you understand okay if you if you still cannot able to understand [00:14:50] we'll try run this brute force approach okay so let's say i'm taking the same example what's that [00:14:55] example is four five two eight ten seven okay so okay uh for the simplification approach okay i'll [00:15:04] i'll also keep the index uh zero one two three four five i think yeah the value i will keep okay [00:15:17] okay i think so value okay i'll keep as four five two ten eight okay and seven okay this is the [00:15:30] index number and these are the values okay so now what we are doing we are taking first i value okay [00:15:37] i equals to zero okay loop started okay now the current element is current element is r4 okay now [00:15:46] it will say look at the right okay why it will say look at the right because our second for loop [00:15:53] is also started which is starting from the i plus one if i is starting from the four then i plus one [00:15:59] should be zero plus one which is five okay now it will compare uh compare with five okay [00:16:08] compare with the 5 okay so answer is so answer is 5 okay if you want to show the comparison i [00:16:21] can show that also okay so answer is 5 simple okay now we stop the searching okay why we'll [00:16:32] stop the searching because of this break we got an answer that's where please stop [00:16:39] hey we started the recording right yeah we started the recording so okay we stop the [00:16:54] searching okay because of this break statement okay now now what now we will print the answer [00:17:02] okay print five okay then i equals to one is started okay because we break that so now current [00:17:11] element is five okay then it will first look at two okay is greater than five will say no okay i [00:17:26] am writing in a simple manner only english word so that you can understand guys okay now it will [00:17:32] look at for the next statement okay so according to this okay if this is not greater i'm i'm not [00:17:39] writing any else statement also that's why it will not break okay it will not break because [00:17:45] this condition is not satisfied yet okay that's why it will go to the another i plus two okay it [00:17:51] will go to the another i plus two okay and then it will look it for okay it will look it for [00:17:59] next element which is 10 okay if it if this is a greater it will set uh yes okay sorry yes okay so [00:18:14] so answer is five and uh we'll stop the searching as usual because of this break statement okay [00:18:31] and then we'll paint the 10 okay simply if we will go to the next statement okay [00:18:43] i i equals to 2 okay then go to the i i equals to 2 then what's the current element is 4 4 5 2 [00:18:53] okay currently is 2 uh 2 and then uh it will look look for the right okay [00:19:10] it will look for the right okay then it will ask like it 10 is greater than 2 we'll say yes [00:19:17] okay then stop the searching okay because of this break statement okay and print the answer [00:19:31] print the answer is then okay what we have found out okay now in case of a 10 okay so [00:19:40] what by default answer is storing by default is [00:19:46] is it so by default is storing as a minus one correct because we have to show minus one right [00:19:51] that's why i'm storing so uh in cause of a 10 uh what what is that i equals to three okay [00:20:02] okay now currently current element is 10 okay it will look at the right okay when it will look at [00:20:12] the right it will what appears 8 okay it will compare if 8 is greater than if 8 is greater than [00:20:22] 10 it will say no okay then it will it will like a go through another okay i plus now i equals to [00:20:32] i equals to 3 then i equals to 4 i i plus 4 okay i plus 1 basically okay it will go to the i plus 1 [00:20:39] and will also check for the 7 okay because that condition is not satisfied so that way it will [00:20:46] also check for the 7 okay does 7 is greater than the 10 it will say no okay don't choose okay so [00:20:53] nothing is greater okay now simply so answer is it will not even go to the break okay simply it [00:21:01] print the answer so answer is minus one so it will print minus one okay what we have printed so far [00:21:09] now five okay uh there is a five then there is a ten again there is a ten okay now it's minus one [00:21:19] okay same it will go to the eight eight will uh it will be the current element it will look at [00:21:24] the right side right side will be the seven okay seven is uh seven it will check okay it will not [00:21:31] greater okay it will bring the answer as a minus one so this is the simple approach okay so what [00:21:36] should be the python code okay okay okay so uh how how we will write uh if we are going to write in a [00:21:52] python uh something code so first we will start i can write over here but let's write over here okay [00:22:11] so yeah so i'll write one next creator okay la i'll write one function okay so this is how we [00:22:21] define the one function okay so yeah sorry so this is how we define one function okay uh using def [00:22:32] keyword okay by uh by taking smaller element with the underscore okay you can you can define one [00:22:39] element okay we can define and then we will take the array length okay by array okay then we will [00:22:53] simply let's say we are storing one answer okay answer will be as i said okay minus one okay [00:23:03] two cross n okay so this is an array okay so basically this is an array okay which is storing [00:23:11] minus one okay multiply with the n okay let's say uh the current uh what we have taken the example [00:23:19] as a six okay so length there is six it will simply save the array of length states with the [00:23:27] elements minus one minus one minus one okay so there is a there is a we are storing right [00:23:32] we are we are we are printing also answer okay in the area format okay so that's why we have to [00:23:40] take the answer okay whatever the result also you have to take the eric so that's why i have taken [00:23:46] the eric correct then then for i in a range for i in a range of n okay what i have taken the above [00:24:03] okay in the pseudo code okay so for i in a take of a range okay it will by default start from the [00:24:11] zero position and it will up to go to the n minus one that's why i have taken in the this format okay [00:24:18] then what i have taken for j in a range of i plus one i have to take right so i plus one i'm starting [00:24:27] from i plus one till n till n means it will take from n minus one so range function is always [00:24:33] going from going to n minus one value okay by default so that's why i am taking this as a n [00:24:40] okay then we'll start the program simply what i have written array is [00:24:45] hey one second i didn't take in the i didn't take in the array as input right so how i can define [00:24:57] so this is how we take the input also okay in the function okay then if area of j [00:25:08] is greater than area of i what i have written in above okay then you simply have to [00:25:16] store the uh answer of i answer of i equals to area of j what we have found as a answer okay [00:25:29] correct then what i have written break break okay then you have to return the result also okay [00:25:44] here you will return the result okay so let's say i'm taking this as a four five what i've [00:25:56] taken two uh so a tenth habit then eight seven then i will simply write print [00:26:06] i will simply copy this okay okay so i'll simply copy this okay and then i taken as a [00:26:28] array as a input okay and then it function with a this function will appear okay as an output [00:26:34] okay so this is the simple approach okay which you can print okay now what's the problem okay [00:26:44] if you see uh i think the last class who is asked like a to to show the something complexity okay [00:26:53] right so what's the complexity if we see okay so okay so there is a two type of complexity [00:27:01] in the programming which we say okay so first is time complexity okay now another one is space [00:27:09] complexity correct so no issues you cannot want to see so another one is space complexity okay [00:27:24] so what is the time complexity how we how we calculate the time complexity okay [00:27:29] so the many times you the many times you apply the for loop in the for loop okay [00:27:36] so the your time complexity will be appears okay so right uh if here if you see okay there is a [00:27:45] two for loop and that two for loop is one inside another okay so and what that is up to going n [00:27:52] minus one times okay so we are removing uh we are like it it's going up to the zero to n minus one [00:28:00] time correct if this is going to the 0 or to the up to 1 n minus 1 time okay we are removing the [00:28:10] constants constant means minus 1 okay we are rounding this value as a n okay correct now if [00:28:17] you will see here i plus 1 okay why i am taking uh why i am removing the constant i'll i'll tell [00:28:25] value okay i i-1 and it will also go into the n-1 okay so let's say so tomorrow uh today we are [00:28:36] taking the value as a six okay so that's why constant is matter okay so if we are taking [00:28:44] tomorrow as a 10 lakh 10 million okay so something like bigger values okay so this will not matter in [00:28:50] the long run okay so that's why we are removing the constant and we are keeping it as a simple [00:28:55] okay if i will remove this constant also so overly it will go into the n values okay so if [00:29:02] we will calculate this time complexity okay n cross n okay it is coming as a okay n cross n [00:29:10] okay which is big o value of big o value of n square okay so whatever you are putting okay [00:29:21] so let's say your n value is 36 okay what is the n value n value is your length of the array [00:29:27] so let's say length of your array is like a 6 okay this loop is will run 36 times okay so let's [00:29:34] say you are taking uh something length as a 6 so it will loop run as a 36 second or like a 36 [00:29:40] milliseconds or something like 36 times it will run okay so this uh is it not uh right approach [00:29:49] like a big of n square is coming okay something bigger values okay and what what is the space [00:29:55] complexity as i told you like a big o value okay big o value of n square that that's how we write [00:30:02] okay so big of n square we are we are writing okay what is the space complexity big of n how [00:30:16] how we know that okay so in this case we are taking extra space okay rather than the array [00:30:22] okay rather than the array we are taking the extra space of a result also result function this one [00:30:29] okay so what up to it is going up to the n length we are storing okay so that's why it is going to [00:30:36] the big of n okay so something like that you can able to imagine okay so something you are storing [00:30:43] in a memory okay to the to your array okay you are asking for another n memory okay so that's [00:30:49] how it is calculated as a space complexity hope i am clear to you okay so this problem is we are [00:30:57] repeatedly scanning the same elements only correct so so what should be the like a smart [00:31:05] approach like a uh and where is the problem is lying okay uh where the problem is lying [00:31:14] i'm telling you okay so let's say tomorrow you are keeping your uh greater value here something [00:31:21] like this 20 okay so the loop is okay so we found the greater element as a like this okay [00:31:31] so let's say you are keeping your like a something greater value in the 20 okay here [00:31:38] it will for sure it will run up to the n square time okay because 20 is here it will calculate to [00:31:45] this okay will again calculate to this 10 will again 10 will again go up to the here and it will [00:31:51] calculate it is a greater or not correct wait a second guys yes so it will calculate it will go [00:32:07] go to the up to end time okay so what should be the better approach okay so can you guys tell like [00:32:22] what should be the better approach how how we can do the better so hint is like you can you can use [00:32:33] the stack okay so let me introduce also to the stack okay so in the simple manner stack is [00:32:38] nothing but but you can see daily to daily life like a book of stack okay so something like the [00:32:45] value which you are putting in the uh above element okay so the value we are put the value [00:32:53] you are putting in the first element it will go to the last of the stack okay like a cloth okay [00:32:59] you are putting cloth as a first element so it will go to the down then putting your another [00:33:05] cloth okay it will go to its above okay then you are putting another cloth okay so this is kind of [00:33:10] a stack okay real life example stack you can able to imagine okay so you can able to use the stack [00:33:16] also so can you tell me like a how you can able to use the stack and uh there uh there you have [00:33:25] to compromise with the time and space space complexity okay so we can reduce this time [00:33:31] complexity okay using this stack okay can anyone tell like a using stack we can able to do it but [00:33:49] how uh nobody okay everybody is left i think okay so what's the current approach so so sorry what's [00:35:07] the problem with the current approach okay so there is a repetitive work right so let's say [00:35:16] as i said okay yeah sorry i was like looking at the second follow up okay sorry okay so what's the [00:35:36] like a problem with this so let's say so array is something like this i'm putting random number [00:35:40] oh why should i put random let's say something like this nine eight seven six [00:35:47] 5 4 3 so this is the simple uh yeah 20 okay something like that i have taken okay for the [00:36:02] for the 10 okay it will check to its right side it will not found this like a in the row okay [00:36:09] but this is found okay i have found out okay so that's the 10 check so for the 9 also it will [00:36:16] also found out the 20 okay for the 8 it will also find out the 20 okay so we are repeatedly checking [00:36:24] for the same element right so in this we are repeatedly checking for the same element so let's [00:36:31] say uh this is the worst case i'm taking okay so it's the worst case with the element cannibal to [00:36:37] come okay and you are checking up to the last okay repeatedly checking for the same element [00:36:43] same element same element okay so what we can do we can we can store this element okay in the top [00:36:50] of the stack okay so that it will not again check for the uh element so let's say uh the element is [00:36:57] coming uh to the nine okay so it will check like oh so nine is not a greater element so it will [00:37:04] remove the nine from this array okay so it will remove the nine from this array so it do not have [00:37:12] to check okay for the rest element okay rest of the element won't have to check so what do i mean [00:37:17] like a i'll say you okay i'll say to you okay what is the simple intuition you can able to [00:37:38] understand okay you understand like a step one we are removing the element from the stack okay [00:37:51] because if we see the current element is not greater okay so we are removing the [00:37:57] element from the stack something like that we have we are doing here so for that we have to [00:38:03] start from the this right to left okay so we have to start the like a for loop from the right to [00:38:13] left okay so we'll maintain the both of the things stack and the answer okay so let's say in the [00:38:23] in the simple manner i'm taking okay so stack okay so there is stack is something look like [00:38:31] this only okay so there is nothing on right uh nothing on the right side okay for now okay so [00:38:40] for the element seven okay i'm taking no not taking this okay taking this only okay so i'm [00:38:53] taking this okay uh so for the element seven okay so there is nothing right so therefore [00:39:06] well we are starting from by the way from this okay starting from the last okay [00:39:12] so therefore the answer of five would be okay so again zero one two three four five okay so answer [00:39:35] of the five will be store it is a minus one okay now post the now post the to the stack okay who's [00:39:48] the seven seven with the stack okay now we will push okay so stack is something look like this [00:39:57] will save like this now coming to the current element okay eight okay so for the element eight [00:40:13] it will check for the stack first okay it will check for the stack so what it's right element [00:40:20] is seven okay so right element seven it will ask and check okay so seven is [00:40:28] greater than eight okay it will check okay seven is less than equals to eight right [00:40:37] so seven is useless uh it will get to understand okay what i'm telling to you okay [00:40:48] now pop it okay so seven is useless will crop from the stack because it checked right [00:40:54] we processed one element okay first and we see like its right element is nothing so we [00:41:02] stored answer as a minus one okay now it is it is going for the another element okay which is [00:41:09] right side of it okay again we are checking if that current element is less than or equals to [00:41:15] the if the previous element is less than or equals to the current element okay if it is so [00:41:21] that element is useless [00:41:23] because that is a smaller [00:41:25] so we will [00:41:28] pop it [00:41:28] now the stack is empty [00:41:33] therefore [00:41:35] answer [00:41:40] of 4 is also [00:41:41] I will tell you in the [00:41:44] code also [00:41:44] don't worry [00:41:45] therefore answer is [00:41:55] minus 1 [00:41:56] now who's the 8 [00:41:58] okay if we will push the 8 okay now the stack will be 8 okay now the current element will come [00:42:09] uh the current element will come as a 10 okay so now it will again check okay is there anything [00:42:32] in the stack okay so stack becomes nothing okay so sorry like we are checking okay so stack in [00:42:41] the stack we have a 8 okay it will again check for the 8 is greater than 10 okay yes [00:42:50] then 80 is also useless okay remove the 8 okay remove the 8 okay and stack becomes empty again [00:43:08] okay all right make all okay so stack becomes empty correct now uh so uh after that we will [00:43:26] save the answer also okay so answer of three will be okay answer of three will be minus one again [00:43:34] correct now who's the 10 into the stack okay now stack becomes then okay [00:43:44] then the current element will come okay which is two okay two will come okay two will check okay [00:43:54] if the 10 is greater than two oh sorry 10 is less than two we'll say no okay now what will happen [00:44:06] 10 is so the 10 is greater than two right and because we are processing from the right to left [00:44:13] the top of the stack represents the first useful greater element okay so we are only storing the [00:44:20] top of the stack the useful element only okay so now so now answer of 2 will be [00:44:29] answer of 2 will be 10 okay answer of 2 will be 10 correct we are we are saving also the array [00:44:38] also we are maintaining the answer element okay now we will push the two to the stack okay now [00:44:46] stack becomes two okay now current element will come okay which is five okay now it will see the [00:44:59] stack okay see the stack stack is two or ten so it will check okay this two is this two is like a [00:45:19] less than five we'll say yes okay so two cannot be a match later right right so [00:45:37] pop it now stack becomes only 10 correct now it will check for the [00:45:53] 10 okay so if 10 is 7 5 is it so no [00:46:04] okay so therefore the answer answer of answer of answer of one will be 10 [00:46:18] now you should also push the 5 okay the stack stack becomes 10 or 5 okay so in the top element [00:46:33] so this this one is a top element then this one is a bottom element okay so whatever you are [00:46:39] pushing into the stack so 10 is the in the bottom side 5 is in the top side correct because stack [00:46:46] nature is like that finally correct and then what the current element is current element is [00:46:55] four okay so current element is four so it will check with the five okay so now it will look into [00:47:03] the stack which is ten and five okay now the top element is like a five is less than equals to four [00:47:13] okay okay it will it will say true okay it will say no okay correct let's you know so five is [00:47:23] next letter correct 10 is also next letter okay okay so therefore therefore your answer of a zero [00:47:38] should be five okay so the moment you get your answer it will not check for the next letter [00:47:49] because we have to check only the first grader right we are not going for the next grader when [00:47:54] we are going for the next grader when we are not getting the first grader correct so now we will [00:48:00] post the four also okay to the stack so 10 5 4 so now the final answer okay whatever you we are [00:48:12] maintaining the answer it's like we'll go as a five okay then we are getting the 10 then we are [00:48:20] getting 10 minus 1 minus 1 minus 1 okay so this is the main logic okay this is the smart solution [00:48:31] okay which you can see correct if you want to write the root pool uh sorry if you want to write [00:48:44] the pseudo code for it how you can like for every element okay i'm writing in english only for every [00:48:51] element we are going from the right to right to left okay you should write in this manner first [00:48:58] okay you shouldn't write for that okay and then we are maintaining the while loop okay [00:49:05] why we are maintaining the value and when we have to maintain the while loop when we don't know [00:49:12] where is the end okay so in the for when we have to apply the for loop is you know where is the [00:49:17] end is okay suppose you know that we are going from this to this okay you know the end okay [00:49:22] in the while loop you don't know the end okay where it can go so in that state we can apply [00:49:29] the while loop okay so we are maintaining one while loop well stack is not empty okay [00:49:35] Okay, when the staff is empty, then the other condition is, and the stack top element, if the current element is less, then we will pop it. [00:50:00] Okay, we are popping this. Okay. Then, if the stack is empty, then we push the next element. [00:50:12] So, if the stack is empty, then first of all, we are storing minus one. Okay, in the array. [00:50:20] We are storing minus one. [00:50:25] else okay answer will be the stack top only stack top okay if the stack is empty then we [00:50:42] are assigning minus one okay if stack is not uh empty then we are taking the top element as a [00:50:53] our answer okay correct then we are printing uh we are pushing to the current element okay [00:51:04] current element to be pushed so like that we push the four okay the current element [00:51:09] it will if there is any element it will check for the first first grader then it will check [00:51:14] for the second grader if not found it will check for the third grader okay correct you found out [00:51:22] so let's say uh another element is came like a six okay something i'm imagining okay [00:51:29] so it will check okay next element for the stack this is on the top right it will check like a four [00:51:34] is greater okay no no no four is not a greater it will it will pop okay then it will check for [00:51:40] the five five okay okay five is greater all right no five is not a greater again pop okay then it [00:51:47] will check for the 10 okay 10 is greater yeah 10 is later okay then we will uh storing the [00:51:54] answer as a 10 first okay here we are checking the answer is uh storing as an answer 10 and [00:52:02] the stack top okay then we are pushing to the current element into the top okay [00:52:12] so it will be removed both of the elements and six will be the remaining correct [00:52:19] hope you got it correct if you are going to write the code for it okay how you will do [00:52:28] then you can able to write like a okay you can able to write same like uh where i have written [00:52:34] the code okay so let's uh don't pop this okay so let's say i'm writing next creator okay [00:52:49] create an element okay then i'm taking one array as usual i have taken okay length of the [00:52:58] array okay then i'm taking one result or an answer you can say as a minus one [00:53:12] then i'm taking one stack okay then i'm taking one for loop which is going from last okay [00:53:23] for i in a range where you have to start from [00:53:26] sorry you have to start from you have to start from n minus one okay we are going to [00:53:38] minus one okay we're going like this okay uh i need a range yes i'll tell you what i've written [00:53:51] here okay this is simple like a while stack and stack of a minus one okay [00:54:04] zero for i okay then that dot pop correct if stack okay stack is empty here [00:54:36] if means if stack means it will give you one if this will give you one negative number then it [00:54:42] will come as a boolean value okay so it will come as a boolean value and it will save [00:54:52] minus one correct stack and this one okay that got happened okay with the current element right [00:55:08] we are appending current element we will write like this then we will return [00:55:48] you will return simply the result okay result error correct okay so [00:56:00] hope you're able to getting it okay do you want to try run of it okay okay [00:56:37] do you want try run of it okay want to understand by the way uh if you cannot able to understand [00:56:43] this okay so range is range function is also can able to take like a three values okay so as as [00:56:51] well like a one is a start where you are starting another one is a stop okay where you are stopping [00:56:56] the another third variable is a stepping okay so the step is like a uh suppose your last in [00:57:06] suppose your last index is like a n-1 okay so minus uh five okay so it will put as a [00:57:14] five over here okay and then you are going to minus one okay up to up to last okay [00:57:21] we are checking okay and then uh we are stepping out okay stepping out minus one okay so let's say [00:57:30] if we will process this okay cannot able to understand then [00:57:39] i don't have to go through it but why i have taken let's say we'll give as a like a [00:57:48] we'll give as uh let's say i equals to five first okay i'm copying this okay [00:57:55] 3-paste, 4-paste, 4-paste, 4-paste, 1, 2, 3, 4, okay. [00:58:05] So now this is 4, 3, 2, 1, and 0, correct. [00:58:17] Now we are processing the elements, okay. [00:58:20] So now we will process the elements, okay. [00:58:25] We will process the element, the array of field. [00:58:29] save first then it will go as a seven correct it will go like like like this okay something like [00:58:36] this then you are starting uh from the seven okay then why we need as a minus one as a stop [00:58:48] because python's race range is doesn't include this stop value okay so if like it means like a [00:58:57] stop before the minus one you can if you feel like a confusing okay like [00:59:07] for i in a range you can you are starting from like a zero to n minus one whereas [00:59:14] you you are written like this you will return like this okay you will return like this [00:59:22] then you are going like this sometimes minus two minus three [00:59:32] one and zero [00:59:42] something like that you are going you are writing this [00:59:48] so yeah so this is the way you can like a like a solve okay so in this you won't have to check [01:00:11] okay so i have written this while you okay don't you think that it is going for like a [01:00:17] and okay instead of we are limitizing it it will go for the only big open time okay so time [01:00:25] context it will be big open time you have full any hands okay we are getting any background noise [01:00:37] okay there is another net okay uh means allowing the mic okay meanwhile you can you can solve this [01:00:51] okay meanwhile you can solve okay i'll give you what the hack man who who's [01:01:17] who is rohan rupta by the way and he is unverified yeah so i'm giving you this [01:01:42] okay this link okay how should we know the yeah i'm putting the lab link also okay yeah kindly [01:02:11] please save the last link the reporting comments or in the model yeah i think in the model you can [01:02:17] able to see right and about malik like you can able to know about your email id from your outlook [01:02:29] okay if you go to the outlook and you will log in okay so for the login also you need [01:02:36] general id right so if you will you login already in the teams right you can able to search by your [01:02:41] name if it is not visible in the model then we have to contact with us like uh uh contact to [01:02:54] the sar uh like a professor because he's only he's only like a controlling this i don't have any [01:03:07] access of admin okay uh about one question like a part where is that question wait a second [01:03:19] okay yeah sure i'll repeat okay is that question of sanyam okay so sanyam you can absolutely use [01:03:35] like a reversed okay uh and in many cases it is actually easier to read also okay so [01:03:43] it is a predefined function okay so you can write instead of for i in a range of n minus one [01:03:51] minus one minus one you can write simply as if for uh i in a reversed okay in the array [01:03:59] so you can print the value okay something like that and print it means [01:04:04] okay uh what type of what does it use okay so so it's using uh stack okay [01:04:20] it's using both okay like array and a stack both it's using [01:04:29] with the model if anyone is option they can able to answer and submit later [01:04:33] whatever to submit uh yeah so okay i'll i'll give you one link of excel state where all [01:04:43] this lab links is mentioned with the date okay and the deadline also and you can able to [01:04:52] be able to check it's possible to attach the lecture notes as we watch recording witness [01:05:03] that you have to check for the module okay that you have to check for uh with the sir only [01:05:15] someone said like a time complexity is a space complexity okay uh robin yes like a stack is [01:05:42] you can able to use for the like a see we uh as i said we have to compromise between the time and [01:05:49] the space complexity right so you have to either increase the time complexity or you have to do [01:05:56] by the decreasing the space complexity or either you have to increase the space complexity see we [01:06:03] have taken uh the stack as a another element right another we are storing as a space okay so in that [01:06:09] case we are we are taking two space complexity two of kind of like a we are increasing with the [01:06:16] space right while our time is reduced space is increased okay robin so this is the some kind of [01:06:25] trade-off you can do within this uh yeah uh explain this stack one more time does this lab [01:06:40] contain the mark c yes what type of stack it is what do you mean it is like what type of stack [01:07:03] it is yeah it's already 12 we will go monolithic monolithic is like a uh simply a stack where [01:07:40] you can keep the element in a particular order either either in a increasing or a decreasing [01:07:46] so we are not using something like that but but yeah it's formally used for the [01:07:58] it's formally used for the monotonic type of a stack where you can use so what do you mean [01:08:13] is like you can you you are increasing your space complexity right while you are decreasing your [01:08:21] so that's the main main point okay okay let's move on to the next question [01:08:35] next question is easy kind of things so you can able to do this you don't need to [01:09:01] so this some kind of a sub array kind of things okay if you ever went to sub array [01:09:25] okay uh you are given one integer a okay containing only one and minus one okay [01:09:37] and a sub-array is called balanced if the sum of its element is zero okay you can take as you [01:09:44] you can you have to take as a sub-array okay and whose uh if it is a balanced then [01:09:52] then it's had to give the answer is zero your task is to find the length of its longest balance [01:09:58] sub array and you must be use the stack to help identify the matching positions okay so [01:10:09] for the sub array what you can do what you are coming into the mind okay [01:10:15] the simple input uh the simple input is like eight okay so which is uh we are taking the element okay [01:10:23] So, the numbers are 8, 1, minus 1, 1, if you add this, okay, you are getting as a 0. [01:10:34] That's why your output is 8, okay. [01:10:38] If you will see this one, okay, if you add this, 1 plus 1 minus 1, something to the last [01:10:46] element, your output is like a 0. [01:10:49] So, that's why you are getting 6, okay. [01:10:53] similarly this is one sub array okay so full arrays can be can able to become a sub array [01:10:59] okay and the part of the array is also a sub array hope you understand so how you can do it [01:11:10] like you can use two correlates to count someone is given on prefix some solution for this [01:11:18] you can use the prefix sum this is the optimal answer yeah you can use the prefix sum but but [01:11:28] what should be the proof force approach first like a you should understand that [01:11:32] some kind of things okay so what we can maintain is like a sub array okay [01:11:42] so first we will maintain one then we will maintain minus one then we will maintain [01:11:48] 1, minus 1, 1 [01:11:50] will sum it and see [01:11:52] okay, we are getting, no, no, no [01:11:54] we are not getting, then we will [01:11:56] maintain this, okay, up to this [01:11:58] will sum, we are getting [01:12:00] no, we are not getting, then we will move [01:12:02] further, okay, we are getting, okay [01:12:04] we are not getting [01:12:04] so, something like that we can do [01:12:09] correct [01:12:10] so, we can maintain [01:12:13] the [01:12:14] we don't have to maintain, but [01:12:17] we have to [01:12:19] compromise with the [01:12:23] time complexity here [01:12:24] in the brute force approach. [01:12:26] One is something like here [01:12:47] so let's say one [01:12:50] so this one [01:12:55] and this one [01:12:57] one [01:12:59] okay [01:12:59] one minus one [01:13:08] minus one [01:13:12] six element is given. [01:13:17] you are doing the plus kind of things okay so we are getting zero okay if you will add [01:13:33] so the answer is six so this is the simple problem we are keeping okay now how you will approach in [01:13:40] the brute force manner uh in the simple word what i can say is like you are maintaining one array [01:13:46] okay array of a sub array you're going to one element you are adding it with the zero okay [01:13:53] and then you are getting one first and then you are approaching to the second element [01:13:58] you are adding it you are getting something okay then from the second element okay or like a [01:14:07] you can you are maintaining uh that that only you are adding this and you are checking uh you [01:14:13] are getting is or not okay and then something like that and we're going okay i'm writing full [01:14:23] okay because this is six element minus minus one and then one okay uh one one minus one minus one [01:14:44] one minus one then you was you you are starting from the index one and then you are going like [01:14:54] this so on okay so if you will write in this manner how you will write uh [01:15:00] you are maintaining one max length equals to 0. Then for i in a range, okay, so if you will write [01:15:18] in a group close manner, then I'll write like this for i from 0 to n-1, then you are maintaining [01:15:31] one sum also okay variable then you are taking one another variable j which will maintain the [01:15:40] i plus one value direct from i okay from j from i to m minus one chip then you are summing this [01:16:03] sum plus array of j then we are checking uh another things if sum is equals to equals to zero [01:16:21] then stop there and calculate the length how we will calculate the length we can calculate the [01:16:32] length like this j minus i plus one okay okay up to this okay we can calculate and then [01:16:46] the max length will be the maximum of max length and then current length [01:17:01] correct so it will compare like a what is the maximum length okay previously and then it will [01:17:10] check for the current length okay then it will update the maximum length and it will return [01:17:25] something like that we can do okay uh we need to also write down the [01:17:34] try run for this there is no required right i have written like this you can able to understand [01:17:39] so this is the manner how we are going first we are approaching this first then we are adding this [01:17:46] then we are adding this this this and this okay you can write the python tool for this [01:17:58] like you can maintain one length of the array and maintain one variable and you can do and [01:18:08] what will be the optimal solution that that already given in the comment okay [01:18:13] by the way while i'm explaining i cannot able to see the comments okay [01:18:18] uh so that's why like i i missed your comments mostly you understand this um logic right i don't [01:18:38] need one uh you can write the optimal solution for this and you can submit to that you can write [01:18:51] this solution and you can you can do it just just one second guys [01:19:56] now i'll take the and i'll leave you by 12 40 or something you want [01:20:03] sapna is not there i think sapna janget here is you have more doubts you already asked [01:20:44] yeah i had one more more for a second it was like this it's like a question [01:20:53] so for that means like i have seen it's like can you miss like better it means like [01:21:00] where while explaining just give some [01:21:02] this like real life example for that [01:21:05] so people will better understand [01:21:07] it which one which one [01:21:08] the second one second problem there [01:21:10] but you one minus one this one [01:21:12] so you need uh some [01:21:14] can you explain like [01:21:16] what i'm doing [01:21:18] with examples [01:21:22] you explained the last problem is like can we [01:21:24] can you explain this like this also [01:21:26] okay okay you need dry run i think [01:21:28] you mean that yeah [01:21:28] okay okay i'll explain [01:21:32] i'll take the some data and it's like yeah some example i'll take and so let's see okay let's [01:21:47] take one example let's take that example okay i'll maintain one index here okay so that you [01:22:10] can understand what i am going for so uh it's not a optimal approach this is a brute force approach [01:22:24] only okay we need to find out the optimal one so initially i'm maintaining one max length as i [01:22:34] said here okay by the way this is the pseudo port not a python team okay so max length i'm [01:22:45] maintaining first we are going to i equals to zero okay we are starting first okay now our [01:22:53] variable is one at the i equals to zero which you can see here correct and see now [01:23:01] i'm also starting my sum value [01:23:05] right here then i'm starting my j again okay as as going through the code i'm i'm going okay [01:23:22] what i've written here okay now add one okay so as i as you go through this okay what does it mean [01:23:35] sum is 0 which is 0 array of j which is 0 okay array of 0 means which is a 1 okay 0 plus 1 is [01:23:45] 1 okay so now add 1 which is 0 plus 1 equals to 1 okay so now it will check okay it will check it [01:23:59] every time right it will check if the sum is 0 it will say no no no sum is not 0 actually [01:24:05] the sum is uh something about one okay it will not not go through the if loop okay now [01:24:13] sorry to interrupt miss like if sum is not zero that it will pop it out [01:24:17] what if sum is not equals to zero then it will pop it out right [01:24:22] no no it will not will go through the if statement okay okay see what is the current sum now one right [01:24:32] yes yes yes so what is the current sum is like a one so it will say if the if this is a zero [01:24:44] no it's not a zero it will not go through this loop this if statement okay we'll see [01:24:52] the statement will come okay we'll see when it will zero it will go through this okay [01:24:58] So now again it will go through for j. [01:25:01] It will go to the n-1, right? [01:25:04] Okay. [01:25:05] I didn't apply any break statement also so that it will break the whole loop [01:25:09] and it will go to another loop here. [01:25:12] Okay. [01:25:13] So it will go to the for j loop. [01:25:15] Okay. [01:25:18] j equals to 1 is started. [01:25:19] Okay. [01:25:20] Now what j is telling? [01:25:22] Add another 1. [01:25:24] Okay. [01:25:25] So what is the next element is 1. [01:25:28] Okay. [01:25:28] add another one so what is my current sum what was my current sum [01:25:34] sum plus array of a j now one plus one becomes two okay now j equals to two okay which is uh [01:25:50] j equals to two is a minus one i think okay and then it will take it as a current sum okay [01:25:57] now previously we have a 2 okay which is this one okay 2 is a plus 2 plus i'll write like this [01:26:08] for the better understanding like this then it will come as a 1 okay now j equals to [01:26:18] sorry j equals to 3 it will go to the n minus 1 right so it will check okay it's checking its [01:26:29] time okay i'm not going through that but it's checking each time if the sum is zero or not [01:26:35] if the sum is zero okay the moment it comes i'll also like a tell you now what's the j equals to [01:26:44] three is a minus one okay so it will uh check okay current sum okay minus one okay so now [01:27:07] it will take as a zero okay so now we have a balanced r8 sub net okay which is okay [01:27:17] minus one sorry one one minus one minus one correct [01:27:24] its length is how its length is calculated [01:27:28] j minus i plus one right so what is my j is three minus zero plus one okay so three minus zero is [01:27:41] three plus one is four okay so maximum length is now max length is now fourth max length is now four [01:28:01] and then we are calculating like a maximum sub array right we are not even stopping here we are [01:28:09] calculating maximum sub array so it will go through the j equals to 4 then what is the j [01:28:15] equals to 4 is like 1 okay the j add 1 so current element current sum is so far is 0 plus 1 equals [01:28:27] to one okay which is not balanced okay and then the equal to five okay j equals to five and [01:28:43] minus one now is zero okay now maximum length how it is calculated jd edge five minus zero [01:29:16] plus one correct it will come as a six so that's why it will return you return you as six [01:29:35] okay it will like do like this and it will check okay it won't stop here okay why it won't stop [01:29:47] here because we know that we have taken one array which is like a solvable correct [01:29:53] So, now it is completed i equals to 0. Okay. Now it will go from i equals to 1. It will check [01:30:03] like this or the g equals to n minus 1. It will go to the i equals to 2. It will check like this. [01:30:09] Okay. So, this is increasing the n square time. Correct. So, it's going on like this. So, hope [01:30:17] you understand. Yeah, thank you, Aditya. Thank you. [01:30:23] not misliked quite and misliked but i will go through this solution it's like yeah sure sure [01:30:27] thank you so next uh sraddha kamath you're there uh hello yeah yeah uh i'm hard to go yeah hi yes [01:30:52] so the first question we were able to do through stacks uh the second one also has a time complexity [01:30:58] of o of n square because we're using two that's that's what i said like that's what i said like [01:31:04] yeah you're correct like this coming as a big of hands where that's why i told like you you need to [01:31:09] do the optimal approach find out it why it is optimal okay and submit it so that's what i said [01:31:16] okay so this is the brute force approach only this is a simple approach you can able to see [01:31:22] the question and you can able to get out the answer something like that yeah also the first [01:31:27] question you explained stacks but how is the concept of last in first out how is that [01:31:35] applicable so like stack simple rule follow like a last in first out okay there is no [01:31:45] need to any confusion queue is like a first in first out you see so okay no no queues [01:31:52] There is no discussion about the last in and first out. How is it used in stacks? [01:31:58] It's simple. It's used in it, isn't it? [01:32:03] Okay, okay. [01:32:05] I was able to visualize how it was last in and first out. [01:32:09] Let's see. [01:32:11] One second, I'll show the stack. [01:32:15] I'll show the stack like this, correct? [01:32:18] I'll show it like this. [01:32:20] I will see you as a stack. [01:32:27] This is something like this. [01:32:30] Push happens, [01:32:32] which is, [01:32:33] if we can see it here. [01:32:35] So, suppose like this, [01:32:36] for the current moment, [01:32:38] I will take this example. [01:32:41] 10 and 2. [01:32:43] So, 10 will be stored here. [01:32:45] And 2 will be stored here. [01:32:48] Or something like that. [01:32:51] how to use the stack, I will tell you how to use the stack. [01:32:55] What we are making is the next greater element. [01:32:57] If the next greater doesn't get it, then take it to the next. [01:33:00] This is a simple fund for our question. [01:33:04] I have done this. [01:33:06] If the current element is coming, first check it. [01:33:09] First check it. [01:33:11] What is greater? [01:33:13] Okay, let's do this. [01:33:15] If it's greater, then pop it. [01:33:19] is [01:33:26] the [01:33:39] Our stack is 6 and bottom is 10. [01:33:43] So, it will also be the next element. [01:33:45] First, it will check 6 and then it will check 10. [01:33:48] So, it will flow. [01:33:50] Next, second, third, and third element. [01:33:54] So, you have to find this too. [01:33:56] Which element is greater in the area, [01:34:00] you can find this. [01:34:01] Use the public. [01:34:03] Okay, got it. [01:34:05] This is store with the stack. [01:34:07] Okay, got it. [01:34:08] One more request. These assignments are graded. [01:34:14] Yes, I'm telling you that they're graded. [01:34:17] No, no. I didn't have a question. [01:34:20] Do you want to confirm it from the server? [01:34:26] No, no, no. I'm saying that... [01:34:30] No, no, no, no, no. I got that the server is graded. I just checked one more time. [01:34:33] I was just confirming that if it is graded, it would be good if I get an email that the assignment is given with the assignment link. [01:34:48] I will give an Excel sheet because I don't have access to admin. [01:34:54] I will provide an Excel sheet with the deadline and the date will be given and the assignment link. [01:35:03] And that's it, we will not be able to do that. [01:35:05] And if you will forward in the mail, then we can quickly find out that this assignment is going to be able to do that. [01:35:10] I will forward in this one. [01:35:12] If you have a WhatsApp group, then you can chat and pin it in there. [01:35:16] Or I will forward in this one every Sunday. [01:35:19] Yes, okay. [01:35:21] If you don't attend class, then at least you will know that this assignment is going to be able to submit it. [01:35:26] Correct. [01:35:28] Thank you. [01:35:29] Thank you, Sridhar. [01:35:38] Ravi Ramjan Singh. [01:35:39] do you have any doubt like if sometime it will be not able to like attend session then [01:36:22] we can do this code ourself also before meeting also you can [01:36:35] sharing that you will be sharing [01:36:37] like [01:36:39] either sir [01:36:41] mail [01:36:43] module [01:36:45] like [01:36:48] module [01:36:51] access [01:36:51] thank you [01:37:01] manesh [01:37:08] yeah [01:37:13] so [01:37:15] if you are giving any program [01:37:17] So, the program which you are giving in the classroom, right now, whatever you are given [01:37:38] for the assignment, so normally, what is the end date for that one week, right? [01:37:44] One week. [01:37:45] Okay, and which language you can use while solving this program? [01:37:50] Any language, like there is no any boundary of like a language. [01:37:54] See, you have taken AIDs, so that's why I'm teaching in a Python. [01:37:58] That will be useful to you. [01:38:00] But there is no any boundary of language. [01:38:02] You can use any language for this. [01:38:04] Okay, so this is the second class for lab, right? [01:38:09] Correct. [01:38:10] Okay, I think I missed first class. [01:38:13] I couldn't solve the assignment, actually. [01:38:16] No worries. [01:38:17] Then I can submit. [01:38:20] You cannot able to because that is passed. [01:38:23] Although I can able to extend that to another one week. [01:38:27] Whoever cannot able to submit like one is. [01:38:31] I can able to extend up to one week. [01:38:32] You can able to guys submit with the same link only if you have. [01:38:37] Otherwise, I can send again. [01:38:39] Yeah, I can submit one is. [01:38:41] actually when i'm logging into the uh hacker rank okay so there i can see that uh you know uh [01:38:49] empty test lab one i can see that [01:38:54] it was visible yeah that is visible right so if you will if you believe [01:39:03] so if i can submit then it's still valid right yeah it's visible only it's visible now [01:39:10] so no need to extend that right no no no if you can able to submit you cannot able to submit the [01:39:19] mtech lab just a second mtech test lab one i can see uh you cannot able to submit that i'll extend [01:39:31] that to another one week so that whoever cannot able to submit they those guys can able to submit [01:39:38] submit code option i'm getting i think maybe submit submit code option is enabled for me [01:39:47] is available till now yeah i can see submit code and when when i'm opening 12 night of today maybe [01:40:00] maybe uh so when i'm going under mtech test lab one if i'm taking any um question here [01:40:09] and i'm clicking on the soft challenge okay then submit code uh button is enabled for me [01:40:18] you didn't submit it you can able to submit yeah yeah i i didn't submit it yeah any further question [01:40:28] no no no thank you yeah okay thank you i think there is [01:40:42] you people do you have any question i have a question uh actually i was uh can you hear me [01:40:54] yeah i can hear you but yeah i have a question yeah yeah one second one second now is it fine [01:41:02] yeah it's fine actually i have one question here uh i was approached i was like uh [01:41:07] using this approach of stack here for the second question first question i have already solved that [01:41:12] in the second question i have one approach that uh suppose like here we can use a map also like [01:41:17] and traversing suppose if you are searching anything any element using the keys in the in [01:41:21] the map also then the uh like the time complexity would be we go of one right [01:41:28] in case of searching using the keys or using the values [01:41:30] how you can complete like a in a big one you are not searching anything or you are not like [01:41:38] doing anything my plus things you are not raverson here yeah what i would what i was thinking like [01:41:48] if we are going through this tag what i was doing i was just doing the sum of it and wherever i i [01:41:53] was getting uh the value greater than one greater than zero sorry i was just uh putting the value [01:41:59] as one in the stack and if it is less than one sorry less than zero we are I was putting the [01:42:04] value minus one and for the zero I was just putting the zero so that I get the same length [01:42:09] as we have in the array so the length is going to be the same so after that I just need to find out [01:42:16] that what is the longest length in between which I was getting zeros so that will give me the value [01:42:22] of the maximum subarray length where we would be getting the balanced value is it fine like I was [01:42:27] having that approach yeah it's it's fine only with your approach but any questions regarding [01:42:35] this or like any fault in my approach actually i was just trying to solve by my own so i didn't [01:42:43] see actually you were doing you were going through the brute force right brute force yeah yeah correct [01:42:48] so brute force would be all will always be greater than the optimized approach so the brute force is [01:42:54] i think here it would be uh n square we go off n square right [01:43:00] then optimal approach like no no no no yeah brute force it's actually whatever is coming in [01:43:08] in our mind even if we are trying to solve it using the two loops or the three loops nested [01:43:13] loops then obviously because because why i'm solving in this approach is uh one guy cannot [01:43:20] cannot able to solve the problem okay the first approach is coming to that mind is brute force [01:43:26] approach okay so that's why i'm solving in that manner yeah brute force okay fine uh brute force [01:43:33] i i just saw yeah it's fine it's in n square i was just trying to solve it using that approach [01:43:39] and i when i just uh check the uh like the solution on the internet then uh it was using [01:43:46] some other approach using the strat but i like i came up with this approach that's why i thought [01:43:50] to ask you okay anything else no no that was my question actually okay go through that approach [01:44:00] and you can solve with that yeah okay thank you uh okay i think he's not there chatin [01:44:23] Yeah. Hi Aditya. How are you? I'm doing good. What about you? [01:44:30] Yeah. Great. [01:44:31] Aditya, I don't have a question. [01:44:33] Actually, I have a query, uh, the link you are mentioned in the chat, uh, like, uh, [01:44:39] this assessment link is routing us to the hacker rank. [01:44:43] If I am right. [01:44:47] Yes. [01:44:47] Like it will route you to the hacker rank link only. [01:44:51] Okay. [01:44:52] All right. [01:44:53] Uh, okay. [01:44:53] that is my query all right i'm good okay uh abhishek upadha hey hi i'm audible hey are you audible [01:45:14] uh actually just i just wanted to know uh the connected for loop how you have used [01:45:20] like a first question or like second question second second one second or first whichever [01:45:29] oh yeah yeah sure okay yeah please go ahead not this one i think [01:45:42] okay we'll go to the first one only okay so yeah man what's your question um means [01:45:55] how that nested for loop works how that nest nested for loop works you didn't attend at the dry run [01:46:01] but no huh i think you need to look at to the you need to ask to the cpt or like something else [01:46:16] i already repeated man thank you ah sorry yeah hi hello sir yeah hi man [01:46:41] um actually you explain everything very well so i don't have any doubts yet [01:46:46] uh but i just have one small uh request to you that could you please ask the admin to share the [01:46:53] uh lab current link through model assignment since it's graded sir so uh as we like other [01:46:59] assignments uh to moodle the same link will be shared via that assignment so that will [01:47:05] that will be very like helpful for us yeah sure sure sure i'll tell to sir that i had this [01:47:13] yeah thank you so much sir thank you uh vishal reina i think he's not there [01:47:31] ranjay kumar no very nice [01:47:42] gotham bharati yeah are you able to hear me yeah i can't wait to hear yeah yeah you [01:47:57] teach us very well so nothing doubt on this uh only have uh curie this is not technical [01:48:04] is a non-technical question uh regarding uh the last year assignment and then uh what kind of the [01:48:13] questions are coming in the final exam so where we will get that one so if we have the time we [01:48:18] can go through yeah yeah in the final exam you will get able to what else what type of [01:48:25] portion you will get okay let me tell you in the final exam or your final semester and in the mid [01:48:30] semester okay so in the mid semester you will get can able to see both type of question one [01:48:37] is a theoretical question another one is a practical type of solution okay so in the [01:48:42] theoretical question you can able to see there are mcqs okay given or like a msq is given okay [01:48:52] with the theoretical things okay so what do i mean by theoretical is like let's say one bubble [01:48:58] shot is there what is the time complexity of a bubble sort okay so this is the one simple [01:49:03] theoretical question what do i mean by practical is so there is a code block given you okay and [01:49:08] there is a some space given you okay you have to you have to fill that okay so let's say there is [01:49:13] a algorithm is there okay and then some code part is missing okay in that algorithm and that code [01:49:20] part is given in the option okay so all all question will be in the mcqs or either msqs [01:49:26] okay or either mask the following okay so these three kind of questions will be come in the final [01:49:32] in the mid semester okay and these two types of like a uh question will become one is theoretically [01:49:39] and one another one is a practical so yeah hope i'm yeah yeah one more thing sir last year [01:49:48] can we get the last year uh was in paper or anywhere i don't have okay i don't have any [01:49:55] question last year because i'm not preparing for it or similar sample paper like such kind [01:50:02] of things where we can just refer but i i'm not preparing for it so okay thanks thanks a lot yeah [01:50:11] thank you gotham sujit pumar does hi uh hi sir uh yeah good afternoon so my question is like uh [01:50:31] the uh for lab two the approach would be brute force or that we discussed today or it can be any [01:50:38] other optimal approach as well in the in the like a asking the what we have to submit yeah yeah for [01:50:47] lab two you can submit either of one you can submit optimal approach you have you can submit the [01:50:54] brute force approach [01:50:57] sure [01:50:58] and the language can be anything [01:51:01] right it doesn't have to be [01:51:03] okay okay thank you [01:51:05] thank you [01:51:09] K.M. Rizwan [01:51:12] hello hi sir [01:51:18] good afternoon [01:51:19] good afternoon [01:51:21] sir as we can see on the screen [01:51:24] the first code [01:51:25] which was explained [01:51:27] I just had a doubt with the value [01:51:30] for suppose uh we were discussing that the value may look to the right and uh just confirm that [01:51:38] if it's greater than that or not or it returns minus one so what if the right value is also the [01:51:48] same digit which one for suppose if we have the value 4 5 2 10 on the screen then 8 7 yeah yeah [01:52:03] if we have to go with the current element 5 so it looks to the right and it uh okay [01:52:12] gets to know that it's a two which is lesser than five okay what if we have five in that place [01:52:21] in place of two which is the same equal number not greater not less [01:52:29] what is the i can't able to get you to speak louder yeah for suppose if we have the number [01:52:35] five itself after the five in the value i can say like four five five ten eight seven if we have in [01:52:46] that way four five there is a duplicate value you want yeah if for suppose we have in that [01:52:53] way which way like a duplicate value you are asking yeah yeah yes sir it's simply reject right [01:53:07] so let's say we are comparing okay you are getting something uh you're in the middle of this okay [01:53:13] you are something instead of two it's five okay so looking into this do you think this is a right [01:53:25] no right correct yeah yeah so it will simply no it will say no okay yeah i was having that question [01:53:36] so we are not like uh applying kind of this equal correct yeah yeah so that's why it will strictly [01:53:47] less than okay okay thank you yeah sure [01:54:02] yeah actually i want to have like what we want to like what i need to prepare for the next class [01:54:07] so that i'll be uh well prepared before joining this oh what what will be the next class yeah [01:54:14] like what will be the topic that i can prepare uh this topic is given by the sir only uh i think two [01:54:22] three days back of the class i even don't know what should be the next class or like [01:54:29] yeah I'm sorry I can't yeah thank you oh by the way thank you guys like a I got so many [01:54:43] requests on a LinkedIn okay could we submit the solution Ryan Marathi yes yeah you can [01:55:05] I went to submit, JC Sarma. Hello. Yeah, hi. [01:55:20] Sir, mughi puchna tha, [01:55:21] joh hacker rank mein, [01:55:22] humare previous submission ko kaisa dheek saakta hai? [01:55:26] This lab man, humne submit kiya tha, [01:55:27] to account. I don't know, [01:55:28] aap saayad hi dheek saakta hai. [01:55:30] I don't think so, aap dheek saakta hai. [01:55:32] So, aapko kuyo dheekhna hai? [01:55:34] Guess pal chalega, [01:55:35] kya humne kitna assignment submit ki hai? [01:55:36] Thank you. [01:55:38] Aapko wohu pata nighi hai, [01:55:39] like, aap itna to accountability rakhna chahe hai. [01:55:43] I don't think so [01:56:06] okay [01:56:12] I am allowing the mic of Vikas and Anand. [01:56:24] Yeah, I have a question regarding lab 1. [01:56:28] So I missed the lab 1. [01:56:29] So I was also trying today. [01:56:32] I submitted the solution. [01:56:34] But I am not able to see the deadline. [01:56:36] The 6 days with lab 2 is pending. [01:56:39] It is not happening with lab 1. [01:56:41] So I doubt that the solution I have submitted has been captured. [01:56:46] So, I guess, I guess, you already were captured because you doubtful that he left one submission [01:56:55] away. [01:56:56] Okay. [01:56:57] So, in that case, the first thing is that you have to submit, which means you got submitted [01:57:11] the live one and then I don't know but I'll explore and let you know