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

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

James Q Quick

1 год назад

19,391 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@RetroMan4321
@RetroMan4321 - 09.12.2023 20:19

Extremely helpful to have a human explain through the often confusingHackerRank interface.

Ответить
@makstrek
@makstrek - 24.10.2023 19:11

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!

Ответить
@francisngo
@francisngo - 14.04.2023 07:54

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!

Ответить
@omergatenio6802
@omergatenio6802 - 26.01.2023 01:15

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 <= 'z') || (char >= 'A' && char <= 'Z')) {
token += char;
} else if(token){
tokens.push(token);
token = '';
}
});
console.log(tokens.length);
tokens.forEach(token => console.log(token));
}

printTokens("He is a very very good boy, isn't he?")

Ответить
@nicolasguillenc
@nicolasguillenc - 19.01.2023 22:59

Thank you, I have an interview in 30 minutes. wish me luck!

Ответить
@DavidBcc
@DavidBcc - 19.01.2023 21:49

Seriously? No string.match()?

Ответить
@shayasanova6272
@shayasanova6272 - 06.01.2023 21:24

Really enjoyed watching this, I think its great that you talk through options for one problem. Keep em coming !!

Ответить
@applemaysl
@applemaysl - 27.10.2022 22:50

Please do more of these!

Ответить
@DraxyBearWD
@DraxyBearWD - 26.09.2022 20:19

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("\n");
};

console.log(tokenise(sample));

Ответить
@mikeonthebox
@mikeonthebox - 29.08.2022 00:00

Quokka playing tricks on you. (I would just disable it been how weird it behaves and how distracting it gets printing errors as you type and producing fake outputs) There are double spaces as it should be as shown on the red letters are the bottom after the word boy. One solution that comes to my mind not using regex would be to use replaceAll that way you can even replace all double spaces with just 1 space, and do a trim also.

Ответить
@m4nim4l
@m4nim4l - 27.08.2022 00:04

Something like this will work:
str.split(/[ !@,?]+/g).forEach(phrase => phrase !== "" && console.log(phrase))

Ответить
@jsayubi
@jsayubi - 20.08.2022 19:11

May i know the theme name you are using for Syntax colors?

Ответить
@ulutiu
@ulutiu - 20.08.2022 13:50

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))

Ответить
@eduardom800
@eduardom800 - 20.08.2022 01:46

Great video, lot's of learning here.

Ответить
@lionelt87
@lionelt87 - 19.08.2022 21:50

const tokenize = s => (s = s.split(/[ !,?._'@]/).filter(Boolean), s.unshift(s.length), s);
tokenize("He is a very very good boy, isn't he?").forEach(console.log);

Ответить
@sr_meia_noite
@sr_meia_noite - 19.08.2022 18:32

Here's my solution (I don't program in JS, and I'm not using Regex, as you didn't use too):

solution = (string) => [...string].map(char => ['!', ',', '?', '.', '_', '\'', '@'].includes(char) ? ' ' : char).join('').split(' ').filter(char => char !== '')

Ответить
@komald7048
@komald7048 - 19.08.2022 17:59

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.

Ответить
@suelingsusu1339
@suelingsusu1339 - 19.08.2022 16:54

Convert string to array use the destructuring operator..... const stringArray = [...stringVariable]

Ответить
@avertry9529
@avertry9529 - 19.08.2022 16:27

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?")

Ответить
@mikeonthebox
@mikeonthebox - 19.08.2022 14:11

Personally I would read everything once and then come with questions and read it again, as many of your questions are answered there, like if tokens can be of length 1. Not sure neither if refactoring right away adds any value, if any it makes you wonder, why didn't you wrote it "the effective way" to begin with.

Ответить
@jakubwikacz4558
@jakubwikacz4558 - 19.08.2022 11:23

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 :)

Ответить
@andreh.9300
@andreh.9300 - 19.08.2022 06:20

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));

Ответить
@BrentHarris00
@BrentHarris00 - 19.08.2022 02:56

awesome

Ответить
@MC---
@MC--- - 19.08.2022 02:04

Regex is great, it takes a little bit to understand but is worth the effort to learn.

Ответить
@ianespinosa2685
@ianespinosa2685 - 18.08.2022 23:15

Tkank for this video could you make a serie of this, is very interesting. Regards from México

Ответить
@jasonrm999
@jasonrm999 - 18.08.2022 22:40

const solution = str => {
const strArr = str
.replace(/[!,?._'@]/g, ' ')
.replace(' ', ' ')
.trim()
.split(' ');
console.log(strArr.length);
strArr.forEach(str => console.log(`${str}\n`));
};
solution(`He is a very very good boy, isn't he?`);
Probably missing something (newbie), but it worked with examples I tested with.

Ответить
@ConnecticutAngler
@ConnecticutAngler - 18.08.2022 21:59

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.

Ответить
@jahonjon
@jahonjon - 18.08.2022 21:38

Best 🥷🤞

Ответить
@jessdaniel5881
@jessdaniel5881 - 18.08.2022 21:02

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?

Ответить
@stevenvallarsa1765
@stevenvallarsa1765 - 18.08.2022 20:57

Did I miss an instruction not to use RegEx to split the string? const tokens = s.split(/[ !.,_'@?]+/) in JavaScript.

Ответить
@dan-mba1063
@dan-mba1063 - 18.08.2022 20:12

Here is a way using a regex in split:

const input = "He is a very very good boy, isn't he?";

const tokens = input.split(/[ !,?._'@]+/).filter(s => (s.length > 0));
const output = `${tokens.length}\n${tokens.join("\n")}`;
console.log(output);

Ответить
@JohnDoeX1966
@JohnDoeX1966 - 18.08.2022 19:44

This is absolutely great. Could you do more JavaScript interview prep videos?

Ответить
@christopheanfry2425
@christopheanfry2425 - 18.08.2022 18:59

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. 😉

Ответить
@braveitor
@braveitor - 18.08.2022 18:58

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)

Ответить
@wadecodez
@wadecodez - 18.08.2022 18:55

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.

Ответить
@tamantaman
@tamantaman - 18.08.2022 18:48

Thanks <3

Ответить
@paraschauhan9978
@paraschauhan9978 - 18.08.2022 18:32

What is the difference between instance and object??🤔

Ответить
@ming3957
@ming3957 - 18.08.2022 18:05

Hackerman James

Ответить