JavaScript Mock Interview | Online Interview Questions and Answers (Part 2)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to the second JavaScript walk interview this is where I have interviewed one of you guys my viewers and recorded the session it's just like a real interview except it's not but it has the same excitement and suspense and drama and all the knowledge that you need to get like in a real interview so I have a suggestion you can watch it multiple different ways you can listen to my question to pause the video do your own solution and then resume it to see if it's matches meteor meteor answer or just you do it while while the candidate is doing and see which whose does it faster right but ultimately it's about speed accuracy instant solution and that is workable especially if you're actively interviewing and then this would be a good video for you and if you want to be part of this whole mock interview video series you can do that I'll provide an email address here and you email me and say hey you wanna I wanna be part of the interview and I will I will take your interview so why not just try right yeah and welcome to texted tutorials can you tell me a little bit about like what is your experience with JavaScript and what you've been working on so I can kind of Judge where you are and then we can start to hard from you but I realize it was just maybe a little too abstract so I had like some experience C++ which mostly I don't know I think it's not a good first language to learn because for so that was like my first introduction to programming I didn't program for like three years or so and I ended up studying writing in college and yeah and then just getting back into programming later and then really like it was just a great time to learn JavaScript so that was like maybe two years ago yes since then I've been doing a lot working with rehab Google's puppeteer library for like automating various things at work and then they using goat GS a lot for part of my job is making like lambda functions for like clients and stuffer most of our static sites that just need you know a little bit of their like a contact form or some other basic data fetching kind of stuff on WordPress sites and using javascript there for animations okay okay cool cool all right so I would say you have you know a lot of experience with JavaScript all right so let's start with little bit simpler and then we'll go up as depends on how you do right let's say if I have an array which has you know bunch of elements which are numbers and what I want to do is I wanna add them just you know get out of it okay yep that's that's the that's right approach I think that's the best approach right now I guess if you wanna have a sweeter code all right so all right so let me move on to the second question let's say if I have a function add and I can write it multiple ways right I can say let's do this way and you can same function you can write it this way okay I want you to write this to one function that does both ways and it should basically add two numbers and give me you know three here okay [Music] yeah that's correct this one so you have just like returning a function that takes one yeah okay okay so the next one is more some sort of algorithm okay so let's say if I have an array it's a number array and it has its unordered array right so unsorted should I say and it has you know numbers between one two hundred okay except one number is missing so it could be five work a seven one number is missing and then the array is unsorted so I need to find that number how would I do that so the fact that I already know that there are there are 99 numbers inside yes you can set before loop to iterate through the array and you can keep like a highest number variable and then it's the current item that's being iterated through it's higher than the variable and you can just reassign the variable I don't know I'm sorry sorry I was thinking it could be any number from from the array right yes I I guess you can sort the array is more brute force but you could sort the array and then iterate through each item and expect that the next number or the number being iterated it's the last number plus one and if it's not the case then that must be the missing number maybe not the best way I'm gonna do it but me I can't cuz that yeah sure so you're trying to sort I trying to use a keyboard shortcut the most recent number which is initialized to zero this starts at 1 so if this is not equal to 100 chase them it's not cool ok I'm thinking this takes the array starts the array I think and then it runs through each item of the array and the most recent checked number is not equal to the current number plus one I can beat this one I I think at this point where I get to say it's the first item yes I might need this okay right yeah I think I think this is this is better compared to previous one where you have to you know do the 1+1 because you are here if it's gonna be between one two hundred then yeah you can just use index yeah okay now usually I you know an initially I usually don't give an answer but the best answer here would be you can use a math function so so I'm just gonna I'm just gonna write it here up here so for example let's say R a so I would do something like this so let's say total equal to array dot well well just do then equal to or a dot length and then the total would be well the total of one 200 right would be because this could be n right any any number of array elements so I would say it's usually like a mathematically it's n multiply by n plus 1 divided by 2 right that's usually it is so then I would I would do that okay so that gives me a total one 200 and then I would do let let's say array total equal to array dot reduce I like this T plus I write and the console.log basically it should be total minus the array so that because yeah that should give you the yeah because if one one number is missing then it should be missing from the total right so first you do the total of all n numbers 1 to N and then you do the total of the array where the N is missing one of the number is missing and then you just subtract it yeah but yeah it's more robust but I think yours is also the thing is in an interview may not get the best result or best way to do it but if you can do sort of optimal by which I think you've done pretty good job cuz I've seen a lot of people doing like you know all kind of have five different variables and tracking stuff and all that stuff so yeah so yeah so you got to do whatever you know at the time your brain thinks off right so it's very hard yeah but yeah this is this is the easiest way all right another since I see you using this kind of function a lot let's say function X what is the difference between this kind of function and this kind of function I always make spelling mistakes so what's the difference between this two and in terms of you know whatever like how do you differentiate between this two what are the problems when you use [Applause] expressions I think this is a function statement this is a function expression first is a statement or they call it declaration and the second is okay yeah that's those are good points and I think the one one additional point which a lot of people don't know is that if you want to pass so let's say if I have the second one which is why so the function declaration which is X if you want to pass it to another function let's say if I want to pass X 2 or Y I could do this way but actually what it becomes inside it becomes an expression automatically because you cannot really pass function declaration into another function it will automatically comes expression so the I somewhere somewhere I read if I simply did this it becomes an expression so that's why you know if I let's say if I want to do like a immediately invoked function expression so remember it's a immediately invoked function expression right so it has to be an expression so if I simply did this and in that case you just don't even have to I guess put X here so it's it is yeah it's an anonymous function but it's a you know that automatically becomes yeah expression inside it's kind of really confusing when I started started JavaScript I had to like really dig deeper like one of my video I said that you cannot pass function declaration inside a function X another function and then a lot of people would you know show me that oh I I can I can write this X function and I'm passing here and it works so you're wrong I said no it as soon as you pass it becomes the declaration I mean expression so I think you know then I would say okay well maybe I said it incorrectly I said say you know you can pass it but it you know it becomes an expression try a little bit more brainteaser let's say if I have a you know like a cash register what I'm just gonna call it what is it called till in UK I guess they call it yeah short term form and and it has a let's say penny some an amount of penny so I said 12 pennies inside and then it has some dimes or nickels that's a tentacles and dimes sometimes you know I say thirty dollars or something like that I'm just giving it a numbers but you know it basically has some money in it in a cash register when somebody let's say a cashier needs to give money back to if you purchase something right so let's say five to give back man let's say $20 and 47 cents back right so I need to design a function where it would give me the $20 and 47 cents with the minimum amount of coins plus well these are let's say these are coins dollar is also a coin it gives you mini I need to use a minimum amount of coin so how would you how would you do that tract you like subtract as many whole dollars as I can and then just work my weight down using quarters and octopus [Music] so I'm gonna make sure that I still love I guess maybe go I'll pay the cents first hey cents first I think I think if you pay by sense than you would obviously get maximum out of coins I won the minimum amount of coins oh yeah I want to use like in this instance what I'd like to do is use twenty dollars that quarter like two dimes and that you pennies know that there's so much so I'm just gonna say sure this is a bad thing to do [Music] so dollars nice I'm sure this is probably it is what ain't right excited but but it works yes yes oh yeah no no no so this is the change they're gay yeah you're getting back so you need to give this much back wait I'm not sure I want to do this but I guess I don't want five so okay so okay so the first part is correct though I would say so you get the okay so you get the right amount of dollars the only thing is let's say so here you split right so you get the let's say 20 out right as a dollar so then you simply need to say okay I have till dollars equal to 30 right so I would just basically I don't really need to say I need to subtract it I just need to say if if it's less than if I if my till has less than $20 then I have a problem right otherwise I can just give that $20 from the tail right so I'm just gonna clean this here so for example I can I can say if and what one other thing you can do is that you have a total right so let's say penny tall or percent total but it says CT or something right is equal to total multiplied by hundred first of all right so then I have everything in two cents right also what I can do is I can have another object this is little bit complex it's not that simple I can have another let's say something like a value right so dollar dollar is basically nothing but 100 quarter is 25 dime is 10 and there are multiple ways to do it I'm just saying this way is this is 5 and this would be 1 right so now the approach should be you can you can say okay I from the total which is now in cents so this would be this would become if I have a 20 47 then it will be 20 47 right this many cents I need to give back right and since daughter can give in hundred chunks I can say if I divide to 0 4 7 by let's say well do you dot dollar right it would give me the remainder of 47 right yeah the male it should be 47 right so yeah so if I know this should be CT actually so then this would give me the sense all the remainder equal to this right now what I can do is so dollars equal to total minus the remainder right so that should give me the the total dollar which is 20 and I gonna actually divided by the hundred two to make it so it gets a little complex and then I have to do the same thing with the remainder now I go to the next level and I do have to do the same thing I have to say the mannery quarter so it would be similar right so remainder 4 I need to basically 47 divided by 25 and then find that a manger right and then move forward to nickel and then if I'm done then I should if it remainder becomes 0 and then I'm fine I'm done okay otherwise I just keep or sometime I don't have enough money in the cap and they're just all right so and I can actually do a loop also because I just need this much logic right so I can loop through it and I have to a priority is that a dollar comes first and then you know so I can I can loop through as well if I want to so there there are multiple solutions but yeah but I think the trick is to bring everything into one unit which is sense right because if you have if you look at the dollar and cents then you you know it kind of it gets confusing yeah one of the interview that I gave I had I had this question and it was like it took me like almost like a half hour to finish it it was like I read like you know because you have to think you know instantly right so you have to do whatever whatever the first thought comes in your head right they to you has already thought about it I said I was able to finish and but it was just like my whole it was a whiteboard question so my whole whiteboard was filled with code right yeah and another thing you have to we have to think about it when you're given a question we get stuck into what the question is asked and what are the parameters then they have given to us right so we only think in that scope okay how do I you know rather than expanding it's okay I want to think beyond what what they given us how can I improve this in terms of like okay I can actually because I remember when I when they give me this question they simply just say oh I have two dollars three cents and then I started from there like is an argument to a function right and then I okay and then after I finished it it was so much messy then the guy said oh how about if you create an object with all the values inside and I was like oh yeah that makes sense but now is today that's another trick yeah let's say if I have a string called I love JavaScript okay and I won the returning string supposed to be like TP i-r-s CS AV a j eb l i it's a reverse string and reverse words and everything and i give you a hint you can do it in one line it split the letters so if you look at this it's actually it's just that ever string it's you don't have to if you split by let's say if I split like this letter by letter and then just reverse it and and then join that's it because I hadn't tricked you usually enough because I said word is reverse and just reverse the whole string I want the reversed of the words and then reverse also each letter which is nothing but reversing is true the whole string anyway edits so have you said that you know had he said that okay I want a reverse you know like a JavaScript love I right that means reversing the word only so in that case you can just split by space and reverse and join by I I think you joined by space as well right and then yeah so this would do it but the first solution is simply a just anniversary it just the way I say it's a trick yeah cuz you probably need you probably knew exactly how it works in the beginning it's just the reverse spring right the species are in illusion yeah that's pretty much it yeah but I think you did well I think you are your commander JavaScript is pretty well I would say I've seen people who you know like struggle even with the syntax you know like but you know all this you're quick on your feet and you know so that's pretty good and this this is where everybody struggle right is the fear is the am I gonna get it right or whatnot right so we start just thinking in the in this little bubble right and so if you if you can expand the bubble and then just think it outside the box so before even you answer it just I would just suggest you stare at the question for a few minutes ask questions right and then I would suggest do it manually what when you do it something manually for example a cent dollar to send one I mean that the cash register one if you had just manually you know created so if I give you an example of $20 and forty cents cents you can if you just break it down into dimes and nickels and all that stuff then you can visualize okay this is how I manually did it so what I would do programmatically would not be that far away okay so that might give you some little bit of different possibilities right the way I explain it it gets stuck in their head and then they'd start following that pattern I would say kind of forget about what they say think of yourself what how what is it what is a question really is right that's the first thing what did they ask what the final result should be and then you kind of bridge the gap the way you like it other than what he wants right because he might give you a constraint and then you can say okay I can work working a constraint but let me see open of the possibility and then you communicate that and then maybe you'll yo like I like the approach when you when you were struggling with the sense and dollars you can say okay you know what I'm just gonna split this by dodge right so that was kind of good thinking on the feet right I am stuck you know this is this is how this is one way to do it right but you said that this is a hack and everything so that's fine but at least I can see your thinking process adding this for him yeah you do you did very better than a lot of people I interviewed for job really what you said about like kind of reading the question like the actual letters or anything like that I'm thinking about corridors like just put everything is there just like you know characters you move around how does stuff like they're not you don't think about the letter something about than words like it's just mine game you know that's that's like a huge takeaway for me because I think the problem with with our brain is when it's in the under pressure it just tries to find the first solution it comes and it gets stuck in in that zone and they just it just takes you to a wrong path yeah yeah because you're trying to struggle there okay I this is a mom now I spend like three minutes on it if I just go keep going I'll find a solution right and that may be the wrong approach yeah so yeah the way to learn is this you know keep that in mind in the back of your head as a tool when you when you go it it's a preparation rather than preparing for JavaScript prepare for this kind of stuff right how do you you know which tool to pull out right rather than you know which function to write okay [Music]
Info
Channel: techsith
Views: 37,127
Rating: 4.9220781 out of 5
Keywords: interview questions and answers, mock interview, mock interview practice, online interview practice, mock job interview, interview preparation, questions for interviewer, javaScript, technical phone interview, skype interview, 2018, 2019, video interview, practice interview
Id: E06YfXKVtGI
Channel Id: undefined
Length: 47min 17sec (2837 seconds)
Published: Tue Jun 26 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.