hey there take East welcome back to Prime coding I am adita and in this video we solve senta September 5 online assessment coding problems and before moving to it there's a small request you can share your coding questions and interview experience let it be of any company to us through telegram WhatsApp Instagram email or LinkedIn okay you can reach out to us in the description you can find all the Social Links which will help you to reach out to us so one of the member who recently reached out to us regarding the essential OA experience and he shared all the oa2 problems both of the problem so we'll discuss each one of them and the essential playlist were very helpful for him and I recommend you as well because that playlist contains coding sheet and their Solutions as well from that sheet you can find the similar or the same questions in this OA as well you can find the same question present in our sheet as well so do check it out now problem statement you are given decimal number n okay I I got it your task is to convert it to Binary and return the sum of its digit okay so the decimal number is 10 and the binary equivalent of this 10 would be 1 0 1 0 okay so the sum of digits is two so we need to return two as we can see the output this question is pretty simple is it so now what would be the code of this or what be the logic behind this program so if you know or you might have studied in your electronics or computer organization where you need to find the binary equivalent of a decimal number okay so how you usually find it so okay let's say I need to convert 2 10 so 2 * 2 * 5 give you 10 so that remainder would be zero 2 * 2 would be four remainder would be 1 because 5 - 4 is 1 and 2 * 1 is 2 which will give you 0er so it is 1 0 1 0 so 1 0 1 0 is a binary equivalent of this T okay so how we found so as I can see the pattern whenever I I was converting it is we need to divide anything any we need to divide the decimal number by two and the quotient whatever quotient we got we need to replace it or we need to append it here and whatever uh whatever the remainder we came up that is the bit that we are looking for okay so yes I found the way okay for finding the remainder I know I can use a modulus operator which will return me a remainder of any divisions operations and for quotient I can either use uh dividend Mark or divisor or I can use u double floor if you I am from python okay so if you are from C++ in Java you can use divide operator not a great thing great so we have cracked down all the logic so for finding the bits we crack down so what all I need I need firstly a binary digit so binary digit yes so let me convert it first okay so binary so you can see binary how I can get it by modulating the given num by given num modulating by two you will get your remainder which is a bit that you are looking for which is this okay and now what you will do you need to divide that particular num as well to reduce the decimal whatever we get after dividing it by two so yeah I will reduce it as well let's say I reduce it by two so yes whatever I will got I will do that here and make sure that each and every variable is initialized with in so that the decimal would be automatically removed okay and if you are from python you can use this flow division okay not a good thing so yes this thing will get your binary bit and reduce the thing so you are done with finding the binary bits now when you got a binary bit at the run time at the run time what you will do is you will create a sum variable and every time make count or sumission of every binary bit that you are finding currently okay so what happened actually is let me rease it and do it for you okay so deci number is 10 as the question given now okay so this line what will we do it will give me a remainder so 2 * 5 would be 10 and it will give me a remainder of zero so what I will do the binary currently the binary has zero so 0o would be appended let's say my sum is also initialized to zero so 0 has been appended here so 0 + 0 is nothing 0 so 2 * 4 2 * 2 is 4 and 4 - 5 - 4 is 1 so I got one binary in the second operation okay in the second operation I got it now binary is currently one so sum plus one would be one so I'm maining the sum as well okay so now 2 * 1 is 2 which will give you zero which will give you zero so sum plus 0 would be again the binary bit is currently zero so 1 + 0 is n so you will get one in the last still your num is not zero so you will append it here and your sum will become two yes so this is the logic behind it and until when you need to operate or you need to do these three task until unless your now will not become zero so now should we greater than zero and you done with your task I hope you got the overall logic how to find the sum of digits because they are not asking us to return the decimal or a binary equivalent of a decimal number if they ask we need to calculate in another manner first thing we need to Traverse and find the binary equalent of decimal number then we need to find the sum of Digit so they directly ask us to find the sum okay so now as we can see the python code so python C++ Java code you can find in the GitHub the GitHub link is the description just over to that there's a repo created with this question name and you will find three of the languages there so def C binary sum n okay so while I initialize my sum in the beginning now while and until unless my numb is greater than zero I need to do this task again and again so again counting the binary which will give me the remainder that I'm looking for which is a bet and as I got the bet I will add up into my sum so that I can make count of every bit okay and as well as I'm reducing it by two so that my y Loop will continue move and in the last I will return the sum and you done with your program you're just calling it just printing it as per the qus required so the time complexity and the space complexity of this code would be o of login because I am directly reducing my decimal number by 2 by2 by2 which is log base 2 N and the space complexity would be constant I'm not considering any auxiliary space to solve this problem which is pretty easy problem you can similarly look to the C C++ program as well where in sum has been initialized doing the same thing while finding out the binary then accumulating into the sum variable and reducing it by n by2 where the time complexity remains same return the sum calling up the function and returning it as per the qus similarly applied in the Java as well similarly no other chains you can find this code in the GitHub as well and TC and SC will remain same for three of the approaches now Shand shames faru and much more students were qualified in ental cognizant and TCS and Prime digital roles without getting demoted in digital so I would say if you want to be a part of this list you just need to take one to one mon as these people took and they got full 1 hour of technical sessions and HR session as well and after that you will get your resume review personalized feedback in which I will let you know about your resume a false part and whatever you need to improve wherever you're langing in your mock session what are your weak Zone what is your strength Zone how you need to take a path of a good way how to crack that particular interview opportunity everything I will let you know and expert guidance as well so you just need to head over to ww. Prime cod.in there is a card that you can find and just reach out to us now write a Python program that reads an integer from user input removes any duplicate values okay and then output the second largest and second smallest unique integer okay so this is the question which were asked recently as well in the August so I would say this is repeated question and you can find the same question guys same question in my enture SD sheet or enture sheet I would say associate engineer sheet that there I ask you to find the smallest or the smallest uh second smallest and second largest elment as well so now how you can solve it now again in this question you I do you think you need to remove duplicates or do that impact our ARR I don't think so okay and for finding it you can either sort your error it's not an issue but I will let you know the optim approach you can sort your array it's not a problem then this return from the back or from the first that the smallest and the Cy can ement not a big thing but here I will let you know the optimal approach of it so how you can do it that particular approach so yes you have 3 1 2 3 4 1 now from the visual effect I can tell you the minimum or the second smallest because smallest is one the second smallest would be two and the largest largest is four and the second largest would be three okay so if anytime I found again again like three is repeated twice so if I found three again my largest would not change my second largest would not change so there is not issue of removing any duplicate they are just letting you to write more quotes which will burn more time so try to be more respective with your time okay and I would say in this particular approach as well people were not able to solve it because people are just converting they are converting the binary first then they are passing to the another function and getting the sum out which is the right approach but it takes lot of time to code and and if you find errors in that then you will messed up because exam pressure is something else so now please try to read the question first and see how much you can optimize that question as per your need okay so what I will do here is let's say I will take example of largest okay finding a largest and second largest element because the logic remains same you just need to change the signs and you are good to go I will tell you in the code as well so what I will do I will find the largest of this element okay so what happened here is see in finding the largest code what is ever you know I guess you might know how to find the largest element present in the array now same code I will just do some Twix into that code and it will return you the second largest as well so see I will find the largest element now for finding largest element I will initialize my largest to a big in minus infinite number okay now what happened here is I will see three first so I know 3 is greater than minus infinite so it will be changed here great so now three now I saw one here so one is less than three yeah it is less than three okay so what I need to do I don't need to do anything now four two now two is less than three yes two is less than three so there is no need because I am countering the largest element so three again do it make changes nothing it will not happen anything if you found a duplicate value as well so now you will get four so yes four now four is greater than three okay so you need to make count of the largest element but what I will do is I will create a second largest variable here as well on the runtime which will preserve the current largest element before initialize reinitializing it okay so currently I found out four and I need to reinitialize my largest but before reinitialize it I will par the number whatever stored by largest to second largest then then I will reinitialize it to four okay now see in the run time I stored the second largest because if four is the largest the previous would be definitely the second largest that I stored here now one do make sense nothing but this will happen in just one if statement but another if statement should also be there such like in this cases one and two okay what will happen here is we need to take count of everything like if we found that my num is greater than second largest okay is greater than second largest and we need to make sure that whatever numb that we are currently on is less than largest or not equal to largest or something else that you want to write okay so this is the particular logic guys it is a very easy logic you need to just change in your first if statement and another if statement would be this then you can easily reinitialize your second largest to the current number okay so this is the two case that you need to write in your fall Loop and you done with the code now I will tell you the exact code that how it will look so let's see then get the second largest thing okay so if Len is less than two this is a base case or I would say a boundary case that you need to take care because it might be the array size is less than then there is no use of finding the second largest okay so I'm dealing it the very first point now largest has been initialized as well as the second largest is also initialized with the minus infinity value okay now what happened here is now see I iting over my nums is it so if I found if I found that my numb is greater than largest just reinitialize my num but before that but before that please store the current value of largest that we I did it here so that if sometime this statement this if statement true then defin itely we need to store the second largest as well so I stored here in the runtime and another case that I discussed with you is if this is not the case if my if statement doesn't go inside let's say if it is sorten but in the descending order let's say 4 3 2 1 and five and something else so this statement won't be executed so you need to check it again do my numbness greater than s largest because it can be the case that you will find the second largest from this if statement yes if it is greater than that and we need to know that then particular num should always be less than the largest which will not hit I will make sure that it will not hit because this case is there okay but still I wrote it for my wellbeing now s largest has been stored and in the last I will return the second largest very easy code it's not a big code okay and it's not a complex code if you didn't understand you can take pen paper and write on dry on it okay you will get this code now second smallest and second largest what is the difference guys there is nothing there is no difference like smallest and second smallest has been initialize with the large positive integer here I initialize with the negative integer and the same for Lo by note the same thing just of greater than I make it less than and whatever we have greater than I make it less okay so here I just use num should not equivalent to smallest it is totally on you okay so now second smallest also been stored and the run time the second smallest also been initialized here so now returning the second smallest and this is your whole code will take the time complexity of O of n because every function has been called after the first function has been executed okay so end space complexity would be overun because I'm not storing any other auxiliary space here as you can see okay so as this array has been demanded by the equ will not consider it as the space complexity so yes I did it and you don't need to write this statement is just for your if you want to run this program you will get an intuitive output okay so yeah this is the particular code of second largest and largest and the C++ code also looks very same second smallest you can see I found it wrote the base case small small and the second smallest has been initialized with the large integer value similarly running a fall then array of I less than small then you need to do some operation and if this case hits you need to reinitialize your second largest and return that respectively and simply we are doing the same thing with the second largest as well where the time complexity and space complexity remains same as you can see here we are passing it and this is a particular format you can find the length of the array as well so calling it and printing it in intuitive manner you don't need to mention the comments inside it okay similarly applies to the Java code no significant difference uh second smallest and the second largest code and there is a main driver code okay so some time complexity remains same so if you want to refer your TCS prepare for TCS nqt prepare for essential or you want a coding sheet which is like you can see in the essential as well whatever question that We Gather in a sheet that similar question is popping into their online assessment and it will app same to CJ mini cognizant TCS and QT I launched every sheet on my channel you just need to head over to it you can find the sheet links and see every sheet link is uploaded on my telegram group there's a rose bot will welcome you if you're new joining to a telegram group and you will get a trial link you can just head over to that you will find every company folder is there and you just need to head over to any of the company that you are looking for to crack you will find the coding sheet there so thanks for watching this video if you are watching till now please do uh please do consider like this video subscribe this channel if you have not and share with your friends so that they can also prepare for their online assessment and crack essential and make their career well so we'll meet you with a new video soon