JavaScript Interview Practice with HackerRank - Strings, Big O Notation, and more!

  Рет қаралды 20,486

James Q Quick

James Q Quick

Күн бұрын

Пікірлер: 79
@DraxyBearWD
@DraxyBearWD 2 жыл бұрын
My solution: const sample = "He is a very very good boy, ins't he?"; const tokenise = (str) => { let output = str.split(/[\s!,?._'@]/).filter((w) => w.length > 0); output.unshift(output.length); return output.join(" "); }; console.log(tokenise(sample));
@surayamelina
@surayamelina Жыл бұрын
So glad I found your channel! This is exactly the kind of video I've been looking for. Great to see an example of what you'd do in a real interview setting and how you talk through all your questions/uncertainties. In my interview prep that's what I've been really curious about, what does it actually look like to solve a problem in real time - glad I'm not the only one asking myself a lot of questions and changing my mind as I go!
@JamesQQuick
@JamesQQuick Жыл бұрын
So glad you enjoyed it!
@RetroMan4321
@RetroMan4321 11 ай бұрын
Extremely helpful to have a human explain through the often confusingHackerRank interface.
@komald7048
@komald7048 2 жыл бұрын
This is a great video, breaking down the thought process on solving these problems. I like the way you went from for loops to more modern using .map() I am looking forward to more.
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ɢᴇᴛ ʜᴇʟᴘ ɪᴍᴍᴇᴅɪᴀᴛᴇʟʏ ɴᴏᴡ ʙʏ ʀᴇᴀᴄʜɪɴɢ ᴏᴜᴛ ᴛᴏ ᴍᴀx ᴛʜᴏᴍᴀs ᴅɪʀᴇᴄᴛʟʏ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ⬆️🆕.
@francisngo
@francisngo Жыл бұрын
I think what is so valuable about this video is that you still expressed confidence in figuring out the problem even when you felt unsure about how something work (e.g. regex). I think how I would approach is talking through the entire problem before coding while I am walking through the problem. Regardless, this video demonstrated break downs of thought process which I found valuable. Kudos!
@JamesQQuick
@JamesQQuick Жыл бұрын
Yeah agreed! Thanks so much for watching :)
@RetroMan4321
@RetroMan4321 11 ай бұрын
Yes it's modeling confidence despite initial uncertainty. This is the goal.
@JohnDoeX1966
@JohnDoeX1966 2 жыл бұрын
This is absolutely great. Could you do more JavaScript interview prep videos?
@JamesQQuick
@JamesQQuick 2 жыл бұрын
That's the plan :)
@adelaykay
@adelaykay 2 жыл бұрын
I've turned on notifications for all videos
@JamesQQuick
@JamesQQuick 2 жыл бұрын
@@adelaykay Yay!
@wadecodez
@wadecodez 2 жыл бұрын
Personally I would have used a single loop and pushed items to an array of arrays. Each time a special character occurs I would start a new array. It would be slightly more efficient because split, join, and filter all imply another loop. Good video though.
@JamesQQuick
@JamesQQuick 2 жыл бұрын
Nice! Thanks for sharing your approach. The good thing is that a finite number of loops (const value) is relatively negligible in terms of Big O, but keeping everything in one loop is a nice tough!
@shakeebarsalan7030
@shakeebarsalan7030 2 жыл бұрын
@@JamesQQuick Theme name please.
@xynyde0
@xynyde0 2 жыл бұрын
@@shakeebarsalan7030 purple
@avertry9529
@avertry9529 2 жыл бұрын
I'll post my answer before watching. Harder than it looks. function res(string) { const split = string.split(/[\W\d]/g) console.log(split.length.toString()) split.map((r) => r != '' && console.log(r)) } res("How are you today, isn't it a lovely day, better than the last 3 days?")
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ɢᴇᴛ ʜᴇʟᴘ ɪᴍᴍᴇᴅɪᴀᴛᴇʟʏ ɴᴏᴡ ʙʏ ʀᴇᴀᴄʜɪɴɢ ᴏᴜᴛ ᴛᴏ ᴍᴀx ᴛʜᴏᴍᴀs ᴅɪʀᴇᴄᴛʟʏ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ⬆️🆕.
@applemaysl
@applemaysl 2 жыл бұрын
Please do more of these!
@shayasanova6272
@shayasanova6272 Жыл бұрын
Really enjoyed watching this, I think its great that you talk through options for one problem. Keep em coming !!
@MC---
@MC--- 2 жыл бұрын
Regex is great, it takes a little bit to understand but is worth the effort to learn.
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
*ᴡᴀᴛ'sᴀᴘ ᴍᴀx ᴛʜᴏᴍᴀs ᴅɪʀᴇᴄᴛʟʏ, ᴛᴇʟʟ ʜɪᴍ ɪ ʀᴇғғᴇʀʀᴇᴅ ʏᴏᴜ ᴛᴏ ʜɪᴍ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ ʜᴜɢᴇ.. 🖤💯☝️
@ConnecticutAngler
@ConnecticutAngler 2 жыл бұрын
Two things I personally would’ve done differently. One is that I tend to use backticks to encompass strings when it’s convenient to avoid issues with literal strings containing single or double quotes; circumvents annoying, cumbersome-looking escapes. The second is that I probably would’ve tried replacing the special characters by doing a forEach loop on the special characters array and running a replaceAll on the source string for each. Great vid! These sorts of tests put developers on the spot, which can be uncomfortable, for sure. But I think it’s great to show the process and how you personally work through it.
@JamesQQuick
@JamesQQuick 2 жыл бұрын
Love it. Thanks for sharing :)
@jakubwikacz4558
@jakubwikacz4558 2 жыл бұрын
Hi James, I have skipped the video this time after few minutes. Consider learning regexp as that is a good tool which you can use everywhere (frontend, backend, sql, searching in text files, converting texts). When you master regexps then you will have another tool in your hands, which will save time :) I do press a like button for a raw approach and a courage to share it as a video :)
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ɢᴇᴛ ʜᴇʟᴘ ɪᴍᴍᴇᴅɪᴀᴛᴇʟʏ ɴᴏᴡ ʙʏ ʀᴇᴀᴄʜɪɴɢ ᴏᴜᴛ ᴛᴏ ᴍᴀx ᴛʜᴏᴍᴀs ᴅɪʀᴇᴄᴛʟʏ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ⬆️🆕.
@ianespinosa2685
@ianespinosa2685 2 жыл бұрын
Tkank for this video could you make a serie of this, is very interesting. Regards from México
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ᴄᴏɴᴛᴀᴄᴛ ᴍᴀx ᴛʜᴏᴍᴀs, ᴛᴇʟʟ ʜɪᴍ ᴛʜᴀᴛ ɪ ʀᴇғᴇʀʀᴇᴅ ʏᴏᴜ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ ʜᴜɢᴇ. ⬆️✍️👆
@nicolasguillenc
@nicolasguillenc Жыл бұрын
Thank you, I have an interview in 30 minutes. wish me luck!
@JamesQQuick
@JamesQQuick Жыл бұрын
Good luck! Let me know how it goes!!
@paraschauhan9978
@paraschauhan9978 2 жыл бұрын
What is the difference between instance and object??🤔
@JamesQQuick
@JamesQQuick 2 жыл бұрын
Well, an instance is typically associated with Object Oriented Programming, where you have an instance of a class. The class is the definition for what an object looks like and the instance is the actual object itself. An object in JavaScript is basically anything that is not a primitive value.
@christopheanfry2425
@christopheanfry2425 2 жыл бұрын
Very instructive video. I think you did it well on your first try but you just forgot to add blank space in your special character variable. Maybe I’m wrong i don’t have the experience you have. 😉
@JamesQQuick
@JamesQQuick 2 жыл бұрын
Well, I don't want to consider a blank space as a special character since it becomes the delimeter when I call .split() at the end.
@christopheanfry2425
@christopheanfry2425 2 жыл бұрын
@@JamesQQuick got it thanks!!
@tamantaman
@tamantaman 2 жыл бұрын
Thanks
@suelingsusu1339
@suelingsusu1339 2 жыл бұрын
Convert string to array use the destructuring operator..... const stringArray = [...stringVariable]
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ɢᴇᴛ ʜᴇʟᴘ ɪᴍᴍᴇᴅɪᴀᴛᴇʟʏ ɴᴏᴡ ʙʏ ʀᴇᴀᴄʜɪɴɢ ᴏᴜᴛ ᴛᴏ ᴍᴀx ᴛʜᴏᴍᴀs ᴅɪʀᴇᴄᴛʟʏ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ⬆️🆕.
@BrentHarris00
@BrentHarris00 2 жыл бұрын
awesome
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ɢᴇᴛ ʜᴇʟᴘ ɪᴍᴍᴇᴅɪᴀᴛᴇʟʏ ɴᴏᴡ ʙʏ ʀᴇᴀᴄʜɪɴɢ ᴏᴜᴛ ᴛᴏ ᴍᴀx ᴛʜᴏᴍᴀs ᴅɪʀᴇᴄᴛʟʏ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ⬆️🆕.
@jsayubi
@jsayubi 2 жыл бұрын
May i know the theme name you are using for Syntax colors?
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ɢᴇᴛ ʜᴇʟᴘ ɪᴍᴍᴇᴅɪᴀᴛᴇʟʏ ɴᴏᴡ ʙʏ ʀᴇᴀᴄʜɪɴɢ ᴏᴜᴛ ᴛᴏ ᴍᴀx ᴛʜᴏᴍᴀs ᴅɪʀᴇᴄᴛʟʏ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ⬆️🆕.
@eduardom800
@eduardom800 2 жыл бұрын
Great video, lot's of learning here.
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ᴄᴏɴᴛᴀᴄᴛ ᴍᴀx ᴛʜᴏᴍᴀs, ᴛᴇʟʟ ʜɪᴍ ᴛʜᴀᴛ ɪ ʀᴇғᴇʀʀᴇᴅ ʏᴏᴜ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ ʜᴜɢᴇ. ⬆️✍️👆
@jessdaniel5881
@jessdaniel5881 2 жыл бұрын
My only comment is you didn’t verify that the solution was still correct after using the Set approach. I was waiting for you to show the full output at the end because “very” appears twice in the input so did that still come out correctly?
@kyleskincoug
@kyleskincoug 2 жыл бұрын
The set was only to contain the special characters for speeding up comparing the token characters to those. The output was still just array so duplicates should still be present.
@JamesQQuick
@JamesQQuick 2 жыл бұрын
+1 to this. Great question though Jess Daniel. I'm glad you called out that I should have re-tested!
@ming3957
@ming3957 2 жыл бұрын
Hackerman James
@stevenvallarsa1765
@stevenvallarsa1765 2 жыл бұрын
Did I miss an instruction not to use RegEx to split the string? const tokens = s.split(/[ !.,_'@?]+/) in JavaScript.
@MC---
@MC--- 2 жыл бұрын
This is the optimal way of doing it. When watching the video I was not 100% sure split could take a RegEx but thought it was likely. I think the global flag is required for cases where there are multiple instances of the special characters.
@Tomapon
@Tomapon 2 жыл бұрын
It's fine to use regex but many people don't know it perfectly without looking it up (like in an interview situation as he mentioned). I think something like .filter(n => n) needs to be added to your solution in order to remove the last empty item in the array? If I only do s.split(/[ !.,_'@?]+/) the array has an empty item in the end, but if I do const tokens = s.split(/[ !.,_'@?]+/).filter(n => n) it seems fine.
@JamesQQuick
@JamesQQuick 2 жыл бұрын
Yeah my take is that many people can't write regex from scratch/memory which is true for me. I thought it would be valuable to show people how I would handle the situation knowing that I couldn't come up with regex on the spot. Hopefully the thought process and being able to adapt is beneficial. I agree though, regex would be a great fit!
@gaborkovacs189
@gaborkovacs189 2 жыл бұрын
@@Tomapon I think your regex is ok, but filter the whole array is unnecessary, because empty element can occur only at the beginning and at the end.
@DavidBcc
@DavidBcc Жыл бұрын
Seriously? No string.match()?
@braveitor
@braveitor 2 жыл бұрын
Another approach: const specialChars = new Set(['!', ' ',',', '?', '.', '_', '\'', '@']) const printTokens = (str, specialChars) => { let tempArray = []; let tempString = ''; for (let i = 0; i < str.length; i++) { const letter = str[i]; if (!specialChars.has(letter)) { tempString += letter } else if (letter!='') { tempArray.push(tempString) tempString = ''; } } return(tempArray.filter(t=>t)); } let filtered = printTokens("He is a very good boy, isn't he?", specialChars) console.log(filtered)
@omerg0101
@omerg0101 Жыл бұрын
you can use the ASCII values when checking the charecters like this: function printTokens(s) { const tokens = []; let token = ''; s.split('').forEach(char => { if ((char >= 'a' && char = 'A' && char console.log(token)); } printTokens("He is a very very good boy, isn't he?")
@peteriannuzzo1525
@peteriannuzzo1525 7 ай бұрын
"He is a very very good boy, isn't he?".replace(/^[^A-Za-z]+/, '').replace(/[^A-Za-z]+$/, '').split(/[^A-Za-z]+/g) .replace(s) will remove all unwanted characters at the beginning and end of string prior to splitting string.
@jasonrm999
@jasonrm999 2 жыл бұрын
const solution = str => { const strArr = str .replace(/[!,?._'@]/g, ' ') .replace(' ', ' ') .trim() .split(' '); console.log(strArr.length); strArr.forEach(str => console.log(`${str} `)); }; solution(`He is a very very good boy, isn't he?`); Probably missing something (newbie), but it worked with examples I tested with.
@lionelt87
@lionelt87 2 жыл бұрын
the .replace() call only replaces the first occurence of a string, so only the first double space gets replaced to a single one. only workaround is to use regex with 'g' (global) flag : 'aa aa aa'.replace(/aa/g, 'bb')
@jasonrm999
@jasonrm999 2 жыл бұрын
@@lionelt87 Yeah I goofed, should have been .replaceAll() (I think that would work) or a regex.
@lionelt87
@lionelt87 2 жыл бұрын
@@jasonrm999 thanks for the replaceAll mention, i nearly forgot it exists!
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ᴄᴏɴᴛᴀᴄᴛ ᴍᴀx ᴛʜᴏᴍᴀs, ᴛᴇʟʟ ʜɪᴍ ᴛʜᴀᴛ ɪ ʀᴇғᴇʀʀᴇᴅ ʏᴏᴜ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ ʜᴜɢᴇ. ⬆️✍️👆
@aham_sammich
@aham_sammich 2 жыл бұрын
const inputString = "He is a very very good boy, isn't he?"; function splitTokens(inputString) { let tokens = inputString.split(/[!,.@'?\s]+/); return tokens.filter(token => token !== ""); } function printTokens(tokenArr) { console.log(tokenArr.length); for (let token of tokenArr) { console.log(token); } } printTokens(splitTokens(inputString));
@JamesQQuick
@JamesQQuick 2 жыл бұрын
Yeah it would help if I could write Regex from scratch which I can't, and I don't think many people can honestly. I think its valuable to show people how you can still solve a problem intelligently in this type of scenario if the regex isn't accessible. That's a great solution though!
@aham_sammich
@aham_sammich 2 жыл бұрын
@@JamesQQuick Of course! Thank you for the video! Your channel has taught me a lot and helped me through several projects recently.
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ɢᴇᴛ ʜᴇʟᴘ ɪᴍᴍᴇᴅɪᴀᴛᴇʟʏ ɴᴏᴡ ʙʏ ʀᴇᴀᴄʜɪɴɢ ᴏᴜᴛ ᴛᴏ ᴍᴀx ᴛʜᴏᴍᴀs ᴅɪʀᴇᴄᴛʟʏ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ⬆️🆕.
@ulutiu
@ulutiu 2 жыл бұрын
const str = "He is a very very good boy, isn't he?" const tokens = str.split(/[^A-Za-z]/).filter(x => x != "") console.log(tokens.length) tokens.forEach(x => console.log(x))
@user-df7gr8no7q
@user-df7gr8no7q 2 жыл бұрын
**ᴄᴏɴᴛᴀᴄᴛ ᴍᴀx ᴛʜᴏᴍᴀs, ᴛᴇʟʟ ʜɪᴍ ᴛʜᴀᴛ ɪ ʀᴇғᴇʀʀᴇᴅ ʏᴏᴜ ғᴏʀ sᴏᴍᴇᴛʜɪɴɢ ɴᴇᴡ ᴘʀᴏғɪᴛᴀʙʟᴇ ʜᴜɢᴇ. ⬆️✍️👆
Javascript Interview Questions and Answers - Dominate Your Next Interview
1:02:33
Monsterlessons Academy
Рет қаралды 73 М.
PIZZA or CHICKEN // Left or Right Challenge
00:18
Hungry FAM
Рет қаралды 16 МЛН
БУ, ИСПУГАЛСЯ?? #shorts
00:22
Паша Осадчий
Рет қаралды 2,6 МЛН
Learn Big O Notation In 12 Minutes
12:18
Web Dev Simplified
Рет қаралды 190 М.
Tips For Using Async/Await in JavaScript
16:26
James Q Quick
Рет қаралды 396 М.
10 JavaScript Interview Questions You HAVE TO KNOW
13:41
James Q Quick
Рет қаралды 69 М.
JavaScript Interview questions everyone gets wrong
6:40
Catherine Li
Рет қаралды 30 М.
5 Tips for Writing BETTER For Loops in JavaScript
16:15
James Q Quick
Рет қаралды 70 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 672 М.
The unfair way I got good at Leetcode
6:47
Dave Burji
Рет қаралды 488 М.
Beginner React.js Coding Interview (ft. Clément Mihailescu)
36:31
Ben Awad
Рет қаралды 2,2 МЛН
Javascript Coding Interview Questions- You Must Know Them
17:06
Monsterlessons Academy
Рет қаралды 18 М.