Live Mock DSA | GeeksforGeeks
Key Takeaways
Conducts a live mock interview for Data Structures and Algorithms (DSA) with Yash Kashyap and Suniti
Full Transcript
[Music] [Applause] [Music] thank you hi hi 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 and roll now Geeks learning together [Music] hi hi are you sure you can prepare for product based companies through this course yes sitting at home no way yes way don't delay enroll now Geeks learning together foreign yes hey uh what do you mean by a self-based course well the course material is available in the form of video lectures and there are multiple practice problems that come along as well so you can access all of it anywhere anytime and they are available to you for Lifetime no way oh yes way don't delay and enroll now Geeks learning together [Music] hi oh so they have access to their job portal in Geeks for geeks for free yes complimentary with the course and you got your job through that me and 15 000 others across the world no way oh yes with don't delay enroll now Geeks learning together hi everyone very good evening to all of you welcome to this amazing live mob DS interview session where we are conducting interviews with our candidates and uh let me first introduce myself my name is suniti and I am a mentor here at Geeks for Geeks so today we are going to conduct our interview with Yash so let us welcome Yash with us hi Yash how are you how are you yes I'm also doing good thank you so uh welcome to this interview session so let us start it so first of all can you please introduce yourself yeah sure um so hello everyone um uh I'm currently pursuing my p-tech and computer science from symbiasis Institute of Technology uh Pune if I talk about my college journey and some of my technical skills I have been doing competitive programming and learning data structures right from my fourth semester when I got into the college um I went ahead to participate in a lot of competitive programming contests uh and my team uh had also been uh the Regional Finance of ICPC uh kanpur regions uh and we secure the rank of 38 in that apart from that I've also participated in contests like Google code Jam Google uh yeah um Google code Jam then Kickstart yeah uh another one which is hosted by Google um then some of the code chef and code forces contest uh and I have also been doing web development recently where I have built uh some projects apart from that I have done two internships uh where the first one was in a research internship that was a n simbasa Center for Medical image analysis and then I went on to do a to do a Hadoop development internship and says matsoft solutions that was in this July itself so yeah all right that was really really a very wonderful interview so uh can you explain about your role while you were working as a Hadoop developer intern so in the time period my work was mostly integrate and develop a new scheduling algorithm under the yarn framework that is a framework in Hadoop so and that I worked with in a team of four to five members where we developed and developed an algorithm and we contributed it to the open source Hadoop uh repository so yeah all right that's really an amazing work and uh thanks for the introduction so before we proceed I will quickly explain to you what we are going to do so a Google doc link has been shared with you right so uh I will be writing down the question in the Google Doc link and then we will be discussing the approach and pseudocode and then once when we are done on that part we will move to the coding part and for that I will share the gfg's practice portals link with you all right and then you can code it there yeah uh that seems right thank you so can you uh vote yeah all right so let us start with our first question and that is given an expression find out if it examples of correct set of parenthesis all right so let me help you with test case sk1 that we have here is all right so if this is the test case then your output for this should be true like as you can see we are having this parenthesis uh like the string that we have in this we have these parentheses all right so as you can see they form a valid pair like why valid pair because as you can see all right this is a brace and then we have a closing Grace here as well and then for this as well we have a closing Grace here and then for these two are already you know uh together so that's where we are cons saying that it is a valid parenthesis combination all right so let us say if another test case I will tell you so okay let me see if this is another test case then for this uh I guess you can predict what will be the output for this the output for this should be false all right so this is your question any queries or anything oh yes so one thing I wanted to ask um are there any specific uh types of parentheses that I only use like in the first stage case I can see only three type of parentheses are used which are the curly braces the square ones and the format that is easy so or can I uh say that so only these three kind of parenthesis will be used till the rest of the test cases as well okay okay so so the first approach that comes to my mind uh will be using a hash maps and a stack so what we can actually do is um we can so if I wanted to highlight we can store the complements of each type of parentheses in a map so for the um so for this type for the square brackets so for this type of um or the square brackets I can store a key value pair uh in my map where the key represents the closing one the closing brackets and the uh value represents the exact complement of that particular parenthesis so all the complements would look something like this uh just a second yeah something like this and then for the large parentheses it would be like this so from using that I can directly get to know about the uh complement of each of the parentheses or even if I don't want it to do that I can also use an FL statement but that would require uh almost two to three uh FL statement but using Maps I can directly use them so now the thing is how do I use uh this information into mesh tag so what I can do is for every pair of um opening brackets uh for opening every opening parentheses um something that comes into mind is I can directly first check is it present inside my map as a key so for the first three parentheses they are not present as a key in my map uh all right so what I'll do is if I get any type of parentheses which is not in my map as a key I'll push it into my stack um what is your key and value like what you are adding as a key and what you are adding as a value yeah so the key uh for every hash map would be the closing uh type of bracket so for the square bracket this would be my key which is the uh closing bracket and the value would be its corresponding uh opening a version so for the curly braces one the left things would be my keys and the right thing would be my values right uh all right okay so okay okay another question that I uh that just came to my mind is is this a valid type of pair uh can I say um something like this uh yeah what this test case give me an answer to no no no this is not a valid combination okay so this is not a valid combination right yeah so my Approach should be fine for this any questions that you wanted to ask yeah like uh I was asking you about the key value pair that you are seeing so like let us say the key you are using is as this closing bracket right so when you will be exhorting the opening bracket so there can be multiple opening brackets right so how are you going to keep the track like if they are getting matched for every pair or not um so yeah that would be included in the logic that I'll be using inside my stack so what I'll be doing is for every pair of opening brackets I'll be pushing it into my stack and uh how do I identify if it's an opening bracket I can just check if it is present as a key in my uh map if it is not present as a key in my map then I know it's an opening type of bracket it's not a closing bracket so I just push it into my stack so for this test case let's say uh I post you are using hashmap just to check if it is an opening bracket or a closing bracket yeah and I would also use to get the complement of those particular brackets uh ahead so initially for this test case what I'll do is I'll push this into my stack all right because it's an opening type of Rocket similarly I'll also push this into my stack and I'll push this into myself so these three uh these three uh symbols would be portion to match that and later on uh the next symbol that I get would be a closing bracket of a square all right so as soon as I get a closing bracket of square I'll check I can check that using uh if it's present as a key so yeah it is present as a key so I'll know that it's a closing bracket so whenever our closing bracket comes I'll just take the top element from my stack and I'll check if the top element from my stack uh like let's say HD is smash that the top element of my stack is equal to the complement of the uh closing bracket so the complement of the closing bracket can be received by this hash map uh I can get that so if it is equal to the complement of the closing bracket I'll just do I'll just pop it out from my stack I'll just uh sorry I just I'll just pop up pop it out and now when I pop it I go to the next symbol so this thing would be removed from a start all right and now these two elements are present at my stack and the next symbol that I would be uh I would be receiving would be a closing parenthesis so again for the closing parenthesis I'll do the same thing I'll check uh is the top element of a stack equal to the complement of the closing bracket so yeah it is equal to the complement of the closing bracket so I'll also pop it from my stack and I'll do the same thing for the uh holy uh prices and I'll pop it as well from the stack and if I arrive at a situation like after performing all the operations if my stack is still not empty or while popping from the stacks I get a situation where the top element is not equal to the complement of the closing bracket I can just return false and I can say that uh that uh that does not resemble the correct set of parentheses all right so or do you think that we really need map here because you use map just to check that if a complement is present out here so I mean you were just doing a simple merchantment right right so uh there was no uh necessity of using Maps uh like I said that would just save me around two to three lines of code because I can directly check that using an FL statement like if the complement of that because I already know the complements of each uh since there are only three types of parentheses but let's say if I had around uh 10 to 50 different type of parentheses then it would be really difficult for me to know the complement of each and every parentheses all right so in that case we would have used map but since the only three parenthesis I can ignore map and I can directly work with the FL statements all right so uh uh do you want to write down the pseudo code or are you comfortable with writing down the code Direct um I can do anything um I can just force quickly write down the suit over uh and then we can move to the code so what I do is I first create a ordered or unordered map doesn't matter let's go for ordered map to avoid any collisions so the type would be of care Karma cap and complement I'll name it as complement and then what I can do is I can insert all the complements to this so the complement for um this would be equal to um the exact opposite of that would be this sorry something like this okay yeah and similarly you can do it for each and every kind of pair so um and I just change the type of parentheses so Photoshop for peanut so once I have all the compliments I can just create a stack of type character and let's name it as p and then um for all the inputs uh let's say the inputs are in the form of uh uh array let's say if we have an array so error so what I can do is I can just do of size n let's say right so I have an array of size n so I can just quickly go through the array can and sort if uh let's say I get an complement already so if I get or closing symbol so complement would be if I get a ARR of I is equal to let's say the closing current disease or I can just copy paste this so I stopped taking uh I stop pushing it to my uh stack like this I'll just break out of my for Loop or else what I'll do is I'll just do St dot uh I can push recommend that so I'll go HD dot push and I can push my error off so once I have pushed all of the stack elements what I can do is I can turn a for Loop um okay so if this condition is true uh I'll have to move to the remaining n by 2 elements since it's that so I can run a follow for impi equal to if you can just clarify me one thing the statement that you have written here is if array of I is any of the closing braces then you are going to break it right like you will break okay yeah right so do you think this code will work fine in this case um okay yeah it was not at or not right so instead of that what I can do is I can I'll not break it um I can just do continue instead of breaking I'll just move to the next element uh so yeah uh if I encounter any of the closing brackets I'll just move to the next element and if it's a opening bracket I'll just push it to my step so after that what I can do is I can go like what you're doing is if it is a closing bracket you are not pushing it inside the stack right and only you are pushing it if it is an opening bracket if it's an opening bracket right right so I'll push all the opening packets from my stack and then what I'll do is I'll start iterating from the back but that word also caused me some trouble [Music] okay so initially what I was thinking was I'll start it rating from the back and if I get any closing parentheses I'll check for the top element but in that case if I get an element like this uh uh or something like this and my attack would not work because this would cause me an issue so okay so I can do that inside this for Loop itself I don't need to stop this I'll not continue it so if I get any of the uh closing brackets I'll just check if it is present at the top of my step okay exactly now you are on the right track so what I can do is I can just do if it's a closing bracket then I check if so attack or I'll just go for the false condition initially if my SP is empty already or my St dot top element is not equal to the complement of error of I and I'll just return oh I'll just return false right okay but if that's not the case then um else what I can do is uh I'll just pop it out from my stack st.com and yeah I think this should work also another statement is if at the end my stack is not empty if HD Dot MP yeah so if my stack dot empty is not correct if it's not true then also I'll have to return false uh or else I'll just return to all right this seems fine and can you help me with again space complexity of the code yeah sure so the time complexity and the space comes with activity for both the uh for my program would be o often or because of n because yeah the time uh we are just uh iterating over each and every element uh once so that would go over all the N elements once and to post that top of it it takes over one time so yeah uh the time complicity would also be n and the suppose space complexity would also be n all right but uh here you are using two linear data structures right map and yeah okay so you have used map here so uh maybe an ordered map will also work here because map will take an extra time complexity as well yeah but I know that map can also work but um yeah okay there's a concept of a collision in maps uh where our map can actually blow up so that would act uh could cause me uh an infinite uh type amount of time to for my solution to execute so just to avoid that issue I just used uh ordered now all right but like here in that case we have already inserted the key value pair so uh like all the key values are different so I guess uh Collision is not going to occur here and uh second of all uh can you tell me the difference between map and an honored map uh yeah sure so uh maps and Maps what happens is whenever we insert a key value pair so all the entries of my ordered map is sorted by its keys so in case of characters it would be sorted by its asci value so who's ever ask value is smaller it would be stored before in my map so the major major difference that occurs is whenever I am searching for an element in my map uh it takes in it uses a binary search internally to find for the element since it's uh not uh since it's ordered so it takes uh an approximate time of login instead of or one but or unordered map it's it uses the concepts of hashing so it uh we can actually access any element in uh the amortized time complexity would be over one for any yeah element in unordered map for searching or inserting what is this concept of hashing like what exactly do we do there right so in hashing it's basically uh you don't put the order you did uh like an autographs everything is ordered uh right it's sorted uh but in another bar we directly use the hash key uh it's hash it's converted encrypted into a hash value and directly using the hash key we can access the elements uh like the value of any key you don't need to do perform a binary research uh in that case okay so but map and unordered map okay ordered or unordered both implements hashing technique right yeah so audit also uh to some extent it uses hashing technique but um again the same thing uh it's it also ensures the order of the elements because it's already sorted so it's uh sorting all the elements in an ascending order uh so that's uh to some extent that might help us and some questions but yeah sometimes it's better to use and ordered Maps like in this case because it would say save us some time all right and if you're instead of an ordered map if you would have used an ordered set would that have created any difference another set oh do you think you can use an ordered setting as well but and another said I can't get key value pairs right so that if I want to find the complement the whole point of creating a map was I wanted to find the complement of any particular element but in sets since it's a data structure where there is a single element present at every uh position I won't be able to get an uh key value pair if I wanted to find the complement of a particular symbol that would be a bit harder yeah great okay so uh I think we are sorted on this part so let us move to the cooling section so I have shared the link can you just open it and put it there like inside the dock itself okay yeah right yeah so yeah sequence less gold spare so it's a strength so I'll try to use some of my code from here to save some time and I'll just edit that okay for this so this should also be returned so now I'm creating an audit map uh on red map that should be the same uh the current disease can be changed for your we need current disease like this so I've created a stack and instead of intn I can what I can do is I can 90 n is equal to short size battery give me the size of the shine so I know I can also put a base case if n is if n is out then my answer would obviously be false so if n is all um and just return false to me or if it's even then this container with uh uh this thing or I don't really need this I guess oh okay so if error of instead of error it should be X if I okay and also have to change this brackets and FST on empty or SD card Automotive complement this should also be X and I just return false as st.com or top or I just push it let me see if I'm missing something let's try to compile it once yeah so it's okay it's not balanced because your output is not value so it's returning me false somewhere let's see why um which will be balanced maybe you can add that line outside the if position that you have written um outside the foundation all right yeah inside the loop but outside the if condition so but in that case if I put it over here so again in this case it would fail right so if I have something like this so when it's uh this is a valid pair but once it has removed the second element from the stack my stack would be empty so before entering this this element into my stack it will check if my stack is empty or not and it would return me false because my stack would be empty as a third index yeah exactly but then you know you should do this push statement in the beginning and then you can check if it is empty or not one thing I would say that you are pushing all the elements inside the stack right as well no I'm not pushing the closing package because if it's a closing packet um then I'm my condition would go into this FL statement and in this FL statement okay yeah right right so that way I said it should be enough so I should also continue from to the next Loop if I'm popping it I should not push it to my stack and this was not an issue so I can put draw the dot and condition over here off and yeah now I guess it should reframe let's see current is spinning of empty uh okay sorry my bad this is in compilation error I guess in parentheses error this starting Market is here this is your for the for loop it's here all right so uh tell me how will your code will execute when we are on the first element of the string itself like uh so it will give turn true for if stack dot empty right stack is empty right now so right yeah and as our stack dot top is not matching to any of the complements so it will try to do stack dot pop but as stack is empty so this pop function can't be performed we give me and it'll give me a runtime error side so okay so what I can do is if it's an even closing brackets only then I should check first after empty I should not initially check it for stock.empty so if it's in closing bracket only then I'll check it for St dot empty or maybe uh like after the for Loop you can write that if you will only push inside the stack if it is and closing like if it is an opening bracket then you will push it inside right yeah so even that should work so I don't think this should make an issue this line even if I comment this line out that would be fine yeah like this so I'll try to submit this it works some segmentation error again so why is that and segmentation error this time yeah so I'll have to check for the flag back empty because it will try to pop the element yes it's in closing bracket at the shot so if the stack is empty I'll just return false so now I'll drag some of those yeah so this one okay all right so okay so now we are clear for this and also like you have used an unordered map here so because you wanted to avoid that flatter that could have yeah so uh instead of avoiding uh instead of using map for avoiding the flatter you could have used switch statement right so it would have saved you some space so you can try that as well all right uh to avoid using Mac okay you can check that whatever the closing bracket you are getting on the top of the stack so you can match it if you know the switch like you can make the switch for the characters and then you can check that if top of the element are getting matched or not right yeah so okay uh that was about this question you did great let us now move to our next question all right okay and that is find out the length of the longest stuff array with something so I will give you a test case let us say because he is that first test case that we have is all right so array that is given to you is 1052719 and the sum that you have to find is 15 right so uh you need to find out the longest sub array which will give you the from 15 right so here as you can see the output will be you need to print the length of the longest substring all right so here at the length of the longest substring will be four because the summary is going to be 527 see as you can see here 10 and 5 will also give you 15 right yeah yeah so that is but this five two seven one this is the longest sub array which is going to give you some 15 so that is our motive here to find out the length of the longest sub array which will give you the sum k okay uh okay uh just a small clarification should always be continuous right yeah some array is a continuous part of an array subsequences are not continuous yeah um Okay so that I can think of is I can maybe use a two-point approach in this um let me just ready for this so what I'm thinking is if we try to keep some pointers so let's start both the pointers from the force element itself and until I get the sum as 15 um or greater than 15 I'll keep on pushing my right pointer let's say we have two pointers Ln R so I'll initially both will point to the first element and if the sum bit we and restore the sum of all the elements between L and R in a variable some variable so until this value of sum is less than 15 what we can do is less than or yeah less than 15 what we can do is we can increment the right pointer to the right and as soon as we get a sum equal to 15 what we can do is we can have another answer variable in which we'll be storing the longest uh some some of the longest sub array um we'll update that as soon as we get a length of 15 a sum of 15 and if we get a sum greater than 15 we can just move uh keep on moving the left pointer to the right until we get the sum has 15 or less than 15. so again if it's 15 we'll update the answer variable but if it is less than 15 we will keep on moving to the right side and we'll keep on doing that until the right pointer cannot move until the right pointer is at the last uh index so yeah I guess Harry contains negative numbers as well okay so it contains negative numbers as well all right yes yes oh spike is in that case the approach that you just said so I think yeah it won't work it would not work yeah right yeah because in case of positive numbers my sum is always increasing as I have move ahead but then negative numbers that would not be the case so exactly Tango something else okay so again uh the first approach The Brute Force approach that we can do is we can iterate over through uh over all the sub arrays all the possible sabaris uh that is possible with this particular array and we can check for the sum if it is 15 then we can just uh pick out the longest uh sabare out of those uh sub arrays so that would be a very nice and uh Brute Force approach uh but the time complexity that would be very inefficient and the time complexity for that would be Big O of n Square because that would be the time taken for to find out all the sub arrays yes now if I want to do a better if I want to make it efficient what I can do is I can have us maybe have a sum variable with 0 with in which I'll be storing a sum and my answer variable which is 0. um okay and for all the elements what I can do is I can add it to my sum button all right uh are you feeling stuck oh I'm thinking uh I have an approach but I'm just verifying if it would work so what I can think of is uh I can like have uh some sort of an hash table where hashma where I can just store the sum and like the indexed apples so from 0 to n minus 1 I'll go through each and every element and I'll just like accumulate all the sums like all the array uh all the error of I so my sum variable and if the sum variable is equal equal to k then again I update my answer uh like my uh answer variable with plus one but if the sum is oh okay so that would be an issue hmm like the intuition that you have we are going to use hashmap that is correct right you can solve this question with the help of hashmap now you just need to you know figure out how hashback can help you here okay so like what is what exactly are you looking for I mean for finding out the longest sub array like which things will help you index values right yeah so uh all the indexes value and the sum maximum value yeah some uh sample that index value I can use that uh okay so ah right so maybe we can use a prefix sum in this um where we can store all the prefix sums uh into my hash map so for 10 I'll store all the like the sum of all the numbers till 10 into my hashma for 5 I can store all the like the sum of all the numbers till 5 in my hashma so I'll store 15 um with the index obviously that 5 uh that I is equal to 1 is the closing index then for 2 again I can store all the sum uh over here all right L7 I'll store uh 7 plus 2 plus 5 plus 10 which is uh I guess 24 with the index and for one and four nine uh two and then what I can do is uh since I know that let's say if I want to check for this about it so what I can do is I can check if the hashmap till or the sum till the last element minus k is already present in my map or not so that that would be maybe this value so if this value is present in my map that means there exists a sub array which will uh determine that yeah I can have array with this particular sum and out of all those sub arrays I'll I can just um get the highest answer and I'll update keep on updating the length of the sub array to my answer so I guess that should work so um if I have something like this I'll store these key value Pairs and my so my key would be um let's see some like the initial value would be my sum so our store 10 is present with the value I NS version or I can just do one because 10 is present once yeah how would I search for some continuous values can you hear me like uh yeah now I can initially I was unable to all right yes like okay so uh see what you can do is maybe you can uh keep on adding all the elements that you have okay like inside the some variables say you can create any variable sum and you can keep on adding all the array elements inside that sum right and then maybe you can check that if you can create a hash map where you will update the index value according to the sum like what would be the key value pair key will be the sum all right and value will be the index value will be the index of that sound okay yeah so then you can check inside your map like for the longest Subaru because you will have indexes of all system that you have till that particular time exactly so you will have all the indexes so that can help you so maybe you can try that approach yeah yeah right um so should I write a word for that yeah first of all let us clear out the pseudocode and then yeah so I can have the initial sum as zero and then what I can do is uh I'll create another unordered hash mark Or Another map of end comment where my keys would be the sum let's give the name as MP and now uh I'll also have my answer variable which will be storing the maximum length or the I can keep it as the sub array line as 0 initially and all iterate through my array less than n i a plus plus okay I go through my array and I'll first add it to my sum the particular numbers of sum plus equal to error of I and after adding it adding the sum to my uh adding the element to the sum variable I can check if there's yeah so if uh there exists a value with uh or there exists an index okay but in that case how would I know that my sum sum minus K so I'm trying to find for some minus K if that is present in my map yes MP of sum minus K how do I know if it is present or not because by default the values would be storing 0 that so it might okay indexing I'm sorry like you just want to check that if some minus K is present inside the map or not right yeah yeah so why not use MP of some minus K is not is equal to MP Dot N is not equal to MP dot end yeah um right I can do that or I can also maybe uh use one base indexing over here and if MP of some minus K is giving me 0 that means it is not storing any value because by default all the values inside this map would be zero zero MP of minus K is equal to equal to 0 then I know that that particular value is not present in my map all right can you just scroll up a little bit because your code is getting hidden by that manner okay yeah uh yeah as you can find now yeah yeah okay so I'll what I'll do is I'll just check if MP of some minus K is equal to 0 I I'll just not do anything or I'll move to connection text but I'll also have to insert this evaluation you'll need to update yeah so I'll uh do MP of sum is equal to I plus 1 because I plus 1 and I'll just continue to the next element continue searching for the next element and I will not update my salary line but if let's say it is present in the map so now I know that there is a sub array which has the sum K so I can just uh initially update my answer so my Safari Land can be updated to MP of sum minus K so that would give me the index so let's say if my index is 1 which is covering it so I I'll also have to put I plus 1 minus that's what I guess give me the length because if I'm at the second second index and I get the sum as this So my answer would be one so yeah I plus 1 minus MP of so minus K should give me the Safari length and once I have the Subaru length I can just add that key value pair to my uh this map so I'll do MP of sum is equal to I plus 1 and yeah once I am done with all of this I can just return the Subaru and whatever I have all right like we need to have the maximum sub array length so do you think that you should be comparing the Subaru elements yeah right right yes so it should be uh I should not directly update it I should take the maximum of sub array length so it is yeah great yeah all right so now this code looks good so can you tell me the time complexity and space complexity of the code all right so the time complexity uh if we talk about another map since inserting and searching for elements take amortized time of one uh the time complexity should be uh it should be linear it should be we go of N and the space complexity should also be off and because we are not having any extra array in this we are just using single variables so yeah both of them would be n great so okay everything seems fine here so now we can move to the coding part yes all right can you please open that link okay so here I have the arid nmk C plus plus Okay so initially or as I did I'll just initialize the sum variable to 0 and my answer variable with also zero and I'll have an unordered map of type and command let's give it as MP and and then I'll just iterate through all the elements so I is equal to 0 IL has been n I plus plus so yeah once I'm inside the for Loop I'll just add it at the sum to my a of I I'll add it to the sum variable I'll just check for the condition if the complement is present so MP of uh something like sum minus a is equal equal to 0 then I'll update the sum to this so update MP of sum equal to I plus 1 uh uh yeah ampere sum is equal to I plus one yeah right and now what I can do is I can just move ahead right I can move it but I guess uh there can be issue with this code because um what if in this case every time the value with the sum is getting updated with the farthest Index right yeah uh but let's say if I have a some variable I have the value of this sub array as 10 and also this sub area is 10 all right so the index that would be getting stored in my map would be of this sub array right exactly so actually there is one condition that you have missed right so there should be another condition which will always store the minimum length of minimum index and with every sum good yeah like you can do that as well but you know just to uh save some uh space and like you know save some statements what you can do is like you are adding all the array elements inside the sum right yeah so if that sum is getting equivalent to k then what you can do is you can directly make your sub array is equal to I plus one uh yeah but that one only right but that uh want that check uh only for the condition if my sabar is starting from the first index is equal to K that yeah that that's the only condition that we are missing right I mean starting from the beginning because all the metal surveys that are being taken care by some minus K when you are checking inside the map so that way if I have uh a sabari like this where I have pen as my first element uh who has my second element so over here my sum is 12. and let's say I have another four so the sum of this Subaru is 4 and then minus 2 2 uh yeah something like this so seven and eight and let's say the required sum is 16 or 15 let it be 15. okay is 15. so what would happen is I'll update 10 to my uh this map I'll update 12 to my map and update 14 uh sorry 16 to my map all right and the value corresponding to 16 would be storing the index of this particular element which which will be 2. but means if I move ahead and if over here also for this ability to the sum would be the same it would be 16. so my sum the index value corresponding to my sum would actually get updated to uh this particular Index right so yes that could give me an issue right because whenever I'm checking for this sum I'll do what the 15 plus 16 that is 31 so I'll check for 31 minus 15 if 31 minus 15 is present in my uh map or not right because the sum for this would be 15. that I want I want this as my salary yeah so like uh whenever you are starting from the beginning I don't think there is any survey which is giving the sum 15 except for 7 and 8. uh no but I'll check for 16 right because uh over here the sum of all the arrays would be uh 31. and I want to get this particular Safari as my answer yeah with some 15. so what I'll do is I'll check for 31 minus 15 if that is present in my area or not right yes even minus 15 will give you 16 right 16 yeah it will give you 16 but there are two sub arrays currently which is giving me the sub area 16. so this one and also this one so like what I will be storing the maximum index that like you can do the I minus MP of some minus K that you have already done there yeah MP of sum would be getting updated to I plus one so my ith would be this 16 will be 5 right yeah yeah so uh you can do and currently like look say let us say currently you are at eight means you are at a seventh position right so you can do 7 minus 5 so that will give you the length 7 minus five fine yeah so that would give me the time which would be this is right exactly so yeah no but I wanted this longest sub array and the longest about is not this the longest the value would be this with the sum 15. right right so if we are checking for so I'll have to make sure that the map variable is always storing the element the earliest element the index of the earliest element with that particular sum okay look at the maximum length so over here what I can do is uh okay so let's just try this uh approach that we discussed and let's see if it fails I'll just make the uh necessary changes so all right okay so yeah I have just shared yeah so Empire is let's continue and then I'll just update the summary after this uh this So my answer would be it was I plus 1 minus maximum of answer comma Max of answer comma I Plus 1 minus my mp of sum minus k this would be my answer and then I'll just update it to my uh answer with some variables so I'll do MP of sum equal to I plus 1 something like this okay and I'll just return the longest about it but I don't think this should work let's see and like oh you can add one more condition that if uh the current sum is coming out to be as equal to k then you can directly return I plus one [Music] but that will always be the longest Circle no that would not be the longest average right because let's say in this particular case from the beginning yeah so let's say over here I wanted the sum as 16 for this particular case I wanted the summer 16. so as soon as I get to 4 my answer variable would get equal to 16 and my program would return 3 to it that would be no less don't return it update the savary length return it yeah right then that's your girlfriend so if my sum is already equal to K yeah then I can just put uh I mean this could be one of our potential answers right yeah right so definitely um that would also be taken care by this one no it could not no no no instead of that I could also put MP of 0 is equal to uh the initial index something like that you you don't need to keep the track of this Max thing here you can just simply update it because I guess if the current index is giving you a value then it will always be there right definitely exactly so as soon as I go ahead in my array it would also it will always get updated to the longest level yeah this works there was in compilation error which capital K not small k right and expected out the matches let's see if it passes all the test cases okay no it does not I guess for the same reason your code output is four so for 15. yeah let me just update that and I'll see if that works so I'll always update this as um can you tell me why you are checking if some minus K is equal to zero you can just check if sum is equal to zero right and so in line number 20 rather than checking if like you are adding the current index value right of MP sum you are updating it like what is the maximum index value that you are getting right yeah so uh checking for some minus K you should just check for some like what is the sum at what maximum index value you are getting a certain sum yeah but if that sum would be zero then yes it doesn't mean that I that I don't include that answer to my answer variable because K code can also be zero right no like you should when you are updating inside the map you are updating MP of sum is equal to I plus 1 right so for that you should check if MP of sum is zero not no yeah rather than writing some minus K you should just write sum there is line number 20. yeah rest everything is fine yes so this time let's see yeah exactly yeah of memory of sum is 0 and also why this contain word discontinuity thing because you know it will not update the answer okay so if my mp of sum is zero that if I don't have that particular sum right yeah so if I don't have that sum I don't uh and if that sum is occurring right now so you will need to add it inside the map yeah so this is what you're thinking okay let's see yeah so first uh oh I know I'm checking if yeah I guess in this issue with this find um you just use the find function that will work well I guess if MP dot finds some is not yeah so because uh like as you said by default every element is having this value of 0 inside the map so yeah right yeah that's that's the issue that's occurring basically so if all right you should be if MP dot finds some is not is equal to m is equal to is equal to MP Dot N because right it won't move like at the point of the last element uh yeah it's a pointer if so if it's not equal to if it's equal to and then I don't have to okay so if it's equal to mp.n and also I guess you can remove that continue statement uh no but in that case it would also yeah let's see continuously and yeah you can remove that line number 26 as well because we are already adding it yeah um we are doing that thing already no but we are only doing if it's equal to mp.10 yeah we are submitting this we're adding it otherwise we are not and I guess you should add an else as well because in in the case if sum is already present then in that case you will update your answer right because sum is already there so in that case you will be updating your answer I'll not update every time yes you would only update if that current sum is present that's present right yes um maybe uh like okay uh I guess I'll need another no I guess you don't need to write I plus one I mean maybe you can you can do with just i y i plus one because now we have uh yeah actually yes we are now not using it so in this case you will need I plus one uh yeah in this one right and also on uh in line number 26 all right so yeah so I'll update but that will that will still be the same if I do I plus 1 over here I'll have to do I press one uh I guess I found the issue oh that was there what I was not doing is I I can instead of this else condition I can take if my um sum minus K is also uh not at the end that means right now I'm only checking if my sum is present or not but I am forgetting about the initial Index right so rather than keeping it inside animals it should be inside and if close only yeah it can be a DOT sign minus k and if it is not equal to MP Dot N that means it is present and it's not present inside my address so I can just update update my answer variable and soft answer from uh if I'm using one patient mixing I'll just do I minus MP of Sun minus that should go all right and correct the spelling of answer yeah sorry okay let's see I guess no oh it's a compilation error oh yeah it should be capital okay again should work thank you finally you solved it so great so uh that was the two questions that we had in today's session now let us move to the feedback part so before going ahead how much would you rate yourself on the basis of this interview session um I would rate myself as a four because I was a little bit stuck in the last debugging part where out of 10. okay okay so out of ten it would be 8 or 8.5 yeah Fair actually see the thing is that first question you did really well um I think that there was some extra time that was being taken but it's okay as at the last you were able to arrive at the approach without any help so uh like there was just normal discussions and uh your communication skills are really great so with the help of that you were able to arrive at the final conclusion right so for the first question it's 10 out of 10 no issues there and in the second question you did need some help right there were some hints required and yeah that is that but your logical part is very strong your communication skills are very strong and so you were able to arrive at the final answer of this question as well and you figured out it yourself only so uh we can have 8.5 for this question all right because there's always a scope of improvement so like you know so let's keep that Gap so 8.5 for this and yeah for the overall interview I would say uh like I would rate you 10 out of 10 for communication skills for your confidence skills and for your logical skills right all of them are really great your problem solving ability is great all right so for that that is 10 and for the problem solving part I will give you 9 out of 10. right yeah so overall it is 9 out of ten and it was a great interview session actually you performed really very well all of the things were decent and yeah the best thing was as I said your problem solving skill and your communication skills are great uh like it it is that if you are having a good communication skills then the interviewer itself feels involved with you right so it was uh like in this session it really felt that it was more of a discussion rather than an interview so that is a very good thing it makes a teamwork kind of environment so that was very good thing about the session so yeah that was a great session so you did great and anything from your side uh no I just wanted to say I really had fun uh discussing all the answers and coming to the solution at the end uh at a point I didn't feel like I was giving an interview it was just a very healthy discussion with my friend uh it felt a sort of oh yeah that kind of a discussion so I had a lot of fun and looking forward to such interviews So yeah thank you so much for having me is your most welcome we hope that these sessions will help you in your preparation journey and we wish you all the best for your future interviewers definitely yeah thank you so much thank you Yash all right guys so uh there was a great interview session by Yash and as we all see he performed really very great and his problem solving skills his communication skills were amazing and that's why this interview session was looking more like a discussion and so that's why it was like kind of uh involving and engaging so I hope all of you will get something to learn and also uh there's one update for you all uh just a second all right guys so there's this winter interview preparation like it is a self-paced course so all of you can join this course and there are many amazing things that you will be taught in this course the course content is there you can go through it and then you can you know check it out all the amazing things that we are doing here like there is this python for data science then data scientists like we have resume tips for placement we have building video library with react and all by we have live mock interview sessions as well on lld we have export tips so there are amazing things that we have there with amazing personalities with the people with for whom you can really learn something we have highly experienced people here so make sure you are enrolling out in this course and you are making yourself interview ready so yeah that's about it and if any of any one of you is interested to join our session so make sure you are filling out the form that is given there in the description of this video and also uh do share out your interview experiences as well with us we'll be very happy to deliver that so thank you guys for joining us and keep up the hard work keep up practicing bye everyone
Original Description
Watch this mock interview to evaluate your strengths & weaknesses alike. A great way for self-examination, make sure to formulate your tactics before your next interview!
In this webinar, we have Yash Kashyap, who will be interviewed by Suniti, Mentor at GeeksforGeeks.
For Complete Interview Prep, visit -https://practice.geeksforgeeks.org/courses/complete-interview-preparation?utm_source=youtube&utm_medium=courseteam_main_desc&utm_campaign=live_mock_dsa
:⛄❄: Winter Interview Preparation :⛄❄: https://practice.geeksforgeeks.org/courses/winter-interview-prep-course-2?utm_source=youtube&utm_medium=courseteam_main_desc&utm_campaign=live_mock_dsa
------------------------------------------------------------------------------------------------------------------
Fill these forms to share your webinars with us:
📝 Live Mock
https://forms.gle/jtkeXRjPxnMvYa1D6
📝 Interview Experience
https://forms.gle/uLjwWXE5fsY5P3Kx9
------------------------------------------------------------------------------------------------------------------
Follow On Our Other Social Media Handles:
📱 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
👽 Reddit: https://www.reddit.com/user/geeksforgeeks
💬 Telegram: https://t.me/s/geeksforgeeks_official
Also, Subscribe if you haven't already! :)
#codingpreparation #coding #techincalround #datastructures #MockInterview #InterviewPreparation #LIVE
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: Systems Design Basics
View skill →Related Reads
📰
📰
📰
📰
The Everyday Backend Engineer: Step 10 — The Observer Pattern
Dev.to · Manoj Khatri
ArborDb: a Rust document store where reading one field doesn't get slower as the record grows
Dev.to · Frédéric Meyer
The 2026 World Cup: A Stress Test For Enterprise Intelligence
Forbes Innovation
Why Interoperability Can Be A Tough Sell In Manufacturing
Forbes Innovation
🎓
Tutor Explanation
DeepCamp AI