I do a mock interview with a developer at work, Cody. He crushes it! Join our Front End Guild Discord server: / discord We built a platform to guarantee your resume gets seen by a human: hackerrelay.com
Жүктеу.....
Пікірлер: 91
@mooosafir74 Жыл бұрын
I like the concept of structuring the interview , very scientific.
@michaelyabut5969 Жыл бұрын
Pretty easy to do it faster than n^2 at home, but I would probably freeze up in an interview lol. I could feel that guys anxiety haha
@michaelyabut5969
Жыл бұрын
Oh just saw the end that it's 2n not n^2 TIL
@lowestCommonDenominator
Жыл бұрын
same, i had an optimal solution in my head immediately but in an interview setting i'm pretty sure i'd forget what javascript even was
@wlgs
Жыл бұрын
its n^2, subStr.includes(currentChar) is kinda innocent but it's O(n), better to use set/hash map here
@MocBocUS
7 ай бұрын
@@wlgs my solution is just loop through the string once and keep track of the longest string and current string so it still be O(n)
@ilichpadilla2448 Жыл бұрын
Do more Interviews like this one. Really helpful video. Keep it
@licokr7 ай бұрын
As a person who preparing for frontend interviews, it really helped. Many people talk about the question because the question may seem like focused on algorithm. I don't know if this is the best interview for the md-level "react" interview though, the point is that. This video is really helpful for me. I really appreciate it you made this video and uploaded it on youtube. Thank you very much! I'm looking forward to further mock interview videos!
@justinmlawrence
6 ай бұрын
Glad it was helpful!!
@thinhbui4090 Жыл бұрын
thanks i really need this
@devzozoАй бұрын
I think a good way to practice would be to copy a hackerrank problems into a react app, display the result(s) in a component, then make an input for the user to see different results from whatever the hackerrank question is asking to do. That seems to be the theme for many of the early-mid level questions. Cody kept saying something along the lines of "Theres probably a better way to do this" and I think that's ok to say, but if you say it too frequently, it makes you seem less confident or qualified. You might want to reword it in a more 'impressive' way by saying something like "I would probably review the documentation to make sure this is the best way to do this...".
@AAmorim19893 ай бұрын
- He did not crush it, he would have been rejected. - This is not a mid level interview, more like an entry level one.
@justinmlawrence
3 ай бұрын
Great feedback!
@cy3889
Ай бұрын
i had the same feeling, he didn't answer the basic technical questions at the start. Feels more like junior level
@horne1395 Жыл бұрын
My first thought about the first problem is to have a way to know which characters has already been iterated to. Maybe something like a Set or a Map, array could definitely be used but that would be O(n). then whenever the current iterated character is already in the set or map, that means we have to reset the tracker.
@guilhermecruz
Жыл бұрын
yeah, Set would be a better choice performance wise
@bennetleff4088
8 ай бұрын
the trick is sliding window
@ASAPKep
6 ай бұрын
I would assume either way the worst case would be O(n) because you still have to iterate through the whole string character by character to append to your map. The implementation here was O(n+n) or O(2n) which is still equivalent to O(n) as the worst case.
@khalidben99405 ай бұрын
The use of Array.includes method will affect the time complexity that will be O(n^2), nested loop so to speak.
@krishnagupta31 Жыл бұрын
In that getTheLargestSubString problem, u can probably use 'continue' to just skip that repeating char that u don't want in ur array
@ahmedAltariqi7 ай бұрын
I remember watching this video when it was released and I didn't understand anything at all. Now, I solved it without watching the video and I feel really happy! 😂
@justinmlawrence
7 ай бұрын
Awesome! 👏🏻👏🏻👏🏻
@ahmedAltariqi
7 ай бұрын
Thanks! Any feedback from you is much appreciated! function getLongestNonRepeatingSubstring(str) { let currentSubstring = ""; let longestSubstring = ""; for (let char of str) { if (currentSubstring.includes(char)) { currentSubstring = ""; } currentSubstring += char; if (longestSubstring.length longestSubstring = currentSubstring; } } return longestSubstring; }
@SuperYoda7 Жыл бұрын
in reality we would use chatGPT for that function and then just build the component.
@user-il9qo4qc4n
6 ай бұрын
nah
@Kreshel17 ай бұрын
react interview... 2 react questions and then 90% of the video a leet code exercise
@davronmaxmudov3972
Ай бұрын
Thanks 😊, you save me 40 minutes)
@user-qj6gf3wv9o Жыл бұрын
Man, I'm struggling to get entry/junior level job and could answer those questions anytime.
@gombosmm Жыл бұрын
Would this not be a junior/entry interview...? I am on that level, and I feel like I could've done exactly the same
@Faith_L3S5-ZERO11 ай бұрын
i won't lie, i did not expect the materials for mid-level position interview would be like this; i understand and can kind of solve the problem by myself which was surprising i always thought that i am more of a junior position guy despite having more than 1.5 yoe because i am never get confident enough of my skills.. but then maybe that's why i am still not good enough for a mid-senior level because i'm still not confident? no telling honestly lol
@quochoangang6014
11 ай бұрын
Same. I'm never get confident enough of my skills too.
@wykydytron
7 ай бұрын
It's what happens to most self thought programmers, because we don't have grades given by teachers and often no one to compare too we think we are still not good. Reality is we very well may be overqualified for junior position but are held back by simple lack of experience and by extention lack of confidence. Then there is whole interview stress thing we're i know fir a fact outspoken confident but weak programmers do better then timid shy but very good programmers it's just how it is, so it's important that interviewer is experienced enough to catch wats going on.
@preslavgetov13304 ай бұрын
I would just add (based on my interview experience) that perhaps stating that you have never touched something or don't know it (in the redux/jotai question) does not really add anything to conversation other then name drop. If you don't have any knowledge to share, a simple don't know about it would suffice.
@duyanhcenland20447 ай бұрын
as a self taugh i feel that its hard to organize what you need to know to get a job
@justinmlawrence
7 ай бұрын
For sure!
@mahmednabil2429 Жыл бұрын
ahh.. btw the solution that they agreed on is not correct, consider "ABCDAFG", their code will output "ABCD" but the correct answer is "BCDAFG". also this is an easy two-pointers problem.
@alexyan125
10 ай бұрын
Coz the loop starts from first character and only went one time.
@yuliasereda56713 ай бұрын
I was wondering about your question smth llike what we get if we pass the component to another component. so, can be the answer that we will get a HOC(high order component) which get and return a component. if we use TS, so we can describe it like React.NodeChild. i'm a junior, so don't judge me please. but can it be the answer?
@mahdijafaree53325 ай бұрын
guys take it easy, as he said it is a MOCK interview haha
@nr7343 Жыл бұрын
He did not complete the exercise. maxLength=currentVal
@Madion869 ай бұрын
Your solution fails on a string 'ABCDAEFGHI'. Your solution answer = 'AEFGHI', correct answer = 'BCDAEFGHI'. Sorry, but dividing by chunks isnt always enough to solve this problem; so your algorithm is wrong from its idea.
@user-zv6bv7eu8k7 ай бұрын
so lost as to how the function knows what the new maxLength is????
@divakarluffy3773 Жыл бұрын
Nice one! hope my interviewer was this kind 😂
@rl6382
8 ай бұрын
Well was he?
@SeRoShadow6 ай бұрын
Now seriously though, is this interview even junior level. I mean I figured in the first 10s that you should create an array to add chunks then sort it by length. And despite this, when I apply for a position, I dont even get an interview call, not even for an unpaid internship position. It makes me feel bad since I self-studied React 2 Yrs. My portoflio is still in building phase, but the ideas I try to execute require extensive development (Job Platform, Company Portal, ECommerce Everything) Should I copy porfolio projects and then rewrite them as my own (while still working on my own projects) , just to get to the interview ?
@justinmlawrence
6 ай бұрын
Let’s chat! discord.gg/4hmnhYpfDg
@berndeveloper9 ай бұрын
I really don't like that much this kind of interviews, because in real life you have an entire world to explore different approaches to hit the best solution. It feels more stressful than a real scenario, if you ask me. Good questions though. (As feedback: Next time don't use music, most of us are listening our own music)
@idanatiya39258 ай бұрын
The interviewer looks like Doctor who
@justinmlawrence
8 ай бұрын
Which one 🤔😅
@richardramirez574610 ай бұрын
Great video, is there anyway to try this with you?
@justinmlawrence
10 ай бұрын
Yeah! Just reach out on our Discord. Always looking for new people! 👍🏻 discord.gg/rFP29feQ
@kashmyr8Ай бұрын
Nice video but I think the candidate overall would have failed in my book. 1. They answered all the React questions in the beginning pretty well. 2. The solution for the coding challenge is pretty much O(n^2) due to the includes nested in the for loop. The solution is not optimal and a pretty messy. 3. The react code was messy. The util method should have been brought in from another file instead of residing in the component. The util function itself should have been "pure" and should not include any React state setter methods. That should be done outside of the util method. Not knocking the interviewee at all though, it's a lot harder under pressure obviously.
@andrewwall27304 ай бұрын
Not sure I understand how the algorithm challenge has anything to do with react. Seems 90% of time not about react. And the code challenge was not well explained. Thought any consecutive same chars should have been eliminated in the results, but guess I was wrong.
@StivenBallshi3 ай бұрын
The solution to this is wrong tho. If we had another string for example str = 'ABCDAEFGH' - the longest string here is 'BCDAEFGH'. The solution cody provided wouldn't work , so you need to check with either the substring method or charAt because you need to see if one of the characters is repeated.
@justinmlawrence
3 ай бұрын
Great catch!
@techmoo55958 ай бұрын
Often, one's posture when sitting can reveal their level of expertise or competence.
@JS_Skyline Жыл бұрын
Instead of using second loop you could use sort method to sort the array from biggest to lowest(arr.sort((a,b) => a.length < b.length ? 1 : -1)) and then return the first element of the array
@nr7343
Жыл бұрын
Sort? Second loop its better bc time complexty Mr russain
@reubz619
Жыл бұрын
Why need to sort the elements when you can just take their length and compare that. Its faster that way!
@lets_see_777
11 ай бұрын
wow you went O(n) to On(logn) complexity and think its better
@sadique_x_5 ай бұрын
chale i no reach!
@21mighty86 Жыл бұрын
3:56 no, correct answer is callbacks
@techaddictdude
Жыл бұрын
Which question?
@21mighty86
Жыл бұрын
Prop drilling state setter does not fit to react flow of data, and it can cause bugs
@JadesFitnessBucketListАй бұрын
really loved watching this, i kept pausing after the question to quickly think about what i would say and how I would write the function before Cody answered. My solution was super similar apart from i used **continue ** in my if block in the loop and at the end to find the longest str in the array i did: return strArr.reduce((longest, current) => { return current.length > longest.length ? current : longest; }, ' ');
@mahmednabil2429 Жыл бұрын
also the real complexity is more than n^2, you should consider the usage of string "+=" operator is O(N) itself
@anasouardini11 ай бұрын
"Mid-level" is kind of meaningless in this exact interview.
@mycraplife Жыл бұрын
Terrible React interview. It was an algorithms interview, which he will never need to use.
@cod-the-creator
Жыл бұрын
No joke, the real life correct answer is "dude, Gary, this API is whack, why are you giving me a bunch of bullshit instead of the thing I need?"
@maiaklimenko6614
27 күн бұрын
At least it's close to a real interview. Everyone asks questions about data structure
@RicardoPerez-gt1vh3 ай бұрын
having a b2 level of english, will be deat on the tree first minute 🤮
@foqsi_7 ай бұрын
Cool video, but so difficult for me to listen to people say "uh" or "um" every other word. haha
@JS_Skyline Жыл бұрын
bthw in Russia this is definitely not a mid-level it’s more like junior or even intern level of knowledge
@prompt9416
Жыл бұрын
bruhh
@Adidobro
Жыл бұрын
yeah new born baby level, rotting in trench soldier level, what else?
@mikejones8519
Жыл бұрын
In Soviet Ruzzia, code write you!
@anasouardini11 ай бұрын
How is my clever (I guess) solution? #!/bin/env node let longestChunckIndexPair = [0, 0]; let firstIndex = []; const setIfLongest = (lastIndex)=>{ if((lastIndex - firstIndex) > (longestChunckIndexPair[1] - longestChunckIndexPair[0])){ longestChunckIndexPair = [firstIndex, lastIndex]; } } const func = (inputStr)=>{ // O(n-1) for(let i=0; i
@justinmlawrence
11 ай бұрын
Awesome!! 👏🏻
@amy_lio Жыл бұрын
Probably smth like that // 'ABCDDDHIGKL' function longestUniqueSeq(str: string) { let maxStr = ""; let bestMaxStr = ""; for (const ch of str) { if (maxStr.includes(ch)) { bestMaxStr = withMaxLength(bestMaxStr, maxStr); maxStr = ch; continue; } maxStr += ch; } return withMaxLength(bestMaxStr, maxStr); } function withMaxLength(str1: string, str2: string) { return str1.length > str2.length ? str1 : str2; }
@BraedenSmith Жыл бұрын
FWIW: Big O on this solution 100% O(n^2) because of the `.includes`.
@gooseob14 күн бұрын
interesting interview! I have a short solution to the algorithm question ```js const longestNonRepeatingSequence = (str) => str .match(/.*?(.)(?=\1|$)/g) .reduce((acc, item) => (item.length > acc.length ? item : acc), ""); ```
@elvado1014 Жыл бұрын
const getStr = (s) => { let startSlice = 0; let longestUniqString = " "; const compareAndSetString = (endSlice) => { const newSting = s.slice(startSlice, endSlice); if (longestUniqString?.length longestUniqString = newSting; } }; for (let i = 0; i const currentLetter = s[i]; const nextIndex = i + 1; const nextLetter = s[nextIndex]; if (currentLetter === nextLetter) { compareAndSetString(nextIndex); startSlice = nextIndex; } compareAndSetString(nextIndex); } return longestUniqString; }
@ondrejvrto3 ай бұрын
My preety solution with reducer. .... Changing the condition to "actualChar === result[0][0]" gives you the second version. const longestUniqueSequention = (str) => { return [...str] .reduce((result, actualChar) => { actualChar a.length .at(0) .reverse() .join(''); } console.log(longestUniqueSequention('ABCDDDDEFGHI')); //
Пікірлер: 91
I like the concept of structuring the interview , very scientific.
Pretty easy to do it faster than n^2 at home, but I would probably freeze up in an interview lol. I could feel that guys anxiety haha
@michaelyabut5969
Жыл бұрын
Oh just saw the end that it's 2n not n^2 TIL
@lowestCommonDenominator
Жыл бұрын
same, i had an optimal solution in my head immediately but in an interview setting i'm pretty sure i'd forget what javascript even was
@wlgs
Жыл бұрын
its n^2, subStr.includes(currentChar) is kinda innocent but it's O(n), better to use set/hash map here
@MocBocUS
7 ай бұрын
@@wlgs my solution is just loop through the string once and keep track of the longest string and current string so it still be O(n)
Do more Interviews like this one. Really helpful video. Keep it
As a person who preparing for frontend interviews, it really helped. Many people talk about the question because the question may seem like focused on algorithm. I don't know if this is the best interview for the md-level "react" interview though, the point is that. This video is really helpful for me. I really appreciate it you made this video and uploaded it on youtube. Thank you very much! I'm looking forward to further mock interview videos!
@justinmlawrence
6 ай бұрын
Glad it was helpful!!
thanks i really need this
I think a good way to practice would be to copy a hackerrank problems into a react app, display the result(s) in a component, then make an input for the user to see different results from whatever the hackerrank question is asking to do. That seems to be the theme for many of the early-mid level questions. Cody kept saying something along the lines of "Theres probably a better way to do this" and I think that's ok to say, but if you say it too frequently, it makes you seem less confident or qualified. You might want to reword it in a more 'impressive' way by saying something like "I would probably review the documentation to make sure this is the best way to do this...".
- He did not crush it, he would have been rejected. - This is not a mid level interview, more like an entry level one.
@justinmlawrence
3 ай бұрын
Great feedback!
@cy3889
Ай бұрын
i had the same feeling, he didn't answer the basic technical questions at the start. Feels more like junior level
My first thought about the first problem is to have a way to know which characters has already been iterated to. Maybe something like a Set or a Map, array could definitely be used but that would be O(n). then whenever the current iterated character is already in the set or map, that means we have to reset the tracker.
@guilhermecruz
Жыл бұрын
yeah, Set would be a better choice performance wise
@bennetleff4088
8 ай бұрын
the trick is sliding window
@ASAPKep
6 ай бұрын
I would assume either way the worst case would be O(n) because you still have to iterate through the whole string character by character to append to your map. The implementation here was O(n+n) or O(2n) which is still equivalent to O(n) as the worst case.
The use of Array.includes method will affect the time complexity that will be O(n^2), nested loop so to speak.
In that getTheLargestSubString problem, u can probably use 'continue' to just skip that repeating char that u don't want in ur array
I remember watching this video when it was released and I didn't understand anything at all. Now, I solved it without watching the video and I feel really happy! 😂
@justinmlawrence
7 ай бұрын
Awesome! 👏🏻👏🏻👏🏻
@ahmedAltariqi
7 ай бұрын
Thanks! Any feedback from you is much appreciated! function getLongestNonRepeatingSubstring(str) { let currentSubstring = ""; let longestSubstring = ""; for (let char of str) { if (currentSubstring.includes(char)) { currentSubstring = ""; } currentSubstring += char; if (longestSubstring.length longestSubstring = currentSubstring; } } return longestSubstring; }
in reality we would use chatGPT for that function and then just build the component.
@user-il9qo4qc4n
6 ай бұрын
nah
react interview... 2 react questions and then 90% of the video a leet code exercise
@davronmaxmudov3972
Ай бұрын
Thanks 😊, you save me 40 minutes)
Man, I'm struggling to get entry/junior level job and could answer those questions anytime.
Would this not be a junior/entry interview...? I am on that level, and I feel like I could've done exactly the same
i won't lie, i did not expect the materials for mid-level position interview would be like this; i understand and can kind of solve the problem by myself which was surprising i always thought that i am more of a junior position guy despite having more than 1.5 yoe because i am never get confident enough of my skills.. but then maybe that's why i am still not good enough for a mid-senior level because i'm still not confident? no telling honestly lol
@quochoangang6014
11 ай бұрын
Same. I'm never get confident enough of my skills too.
@wykydytron
7 ай бұрын
It's what happens to most self thought programmers, because we don't have grades given by teachers and often no one to compare too we think we are still not good. Reality is we very well may be overqualified for junior position but are held back by simple lack of experience and by extention lack of confidence. Then there is whole interview stress thing we're i know fir a fact outspoken confident but weak programmers do better then timid shy but very good programmers it's just how it is, so it's important that interviewer is experienced enough to catch wats going on.
I would just add (based on my interview experience) that perhaps stating that you have never touched something or don't know it (in the redux/jotai question) does not really add anything to conversation other then name drop. If you don't have any knowledge to share, a simple don't know about it would suffice.
as a self taugh i feel that its hard to organize what you need to know to get a job
@justinmlawrence
7 ай бұрын
For sure!
ahh.. btw the solution that they agreed on is not correct, consider "ABCDAFG", their code will output "ABCD" but the correct answer is "BCDAFG". also this is an easy two-pointers problem.
@alexyan125
10 ай бұрын
Coz the loop starts from first character and only went one time.
I was wondering about your question smth llike what we get if we pass the component to another component. so, can be the answer that we will get a HOC(high order component) which get and return a component. if we use TS, so we can describe it like React.NodeChild. i'm a junior, so don't judge me please. but can it be the answer?
guys take it easy, as he said it is a MOCK interview haha
He did not complete the exercise. maxLength=currentVal
Your solution fails on a string 'ABCDAEFGHI'. Your solution answer = 'AEFGHI', correct answer = 'BCDAEFGHI'. Sorry, but dividing by chunks isnt always enough to solve this problem; so your algorithm is wrong from its idea.
so lost as to how the function knows what the new maxLength is????
Nice one! hope my interviewer was this kind 😂
@rl6382
8 ай бұрын
Well was he?
Now seriously though, is this interview even junior level. I mean I figured in the first 10s that you should create an array to add chunks then sort it by length. And despite this, when I apply for a position, I dont even get an interview call, not even for an unpaid internship position. It makes me feel bad since I self-studied React 2 Yrs. My portoflio is still in building phase, but the ideas I try to execute require extensive development (Job Platform, Company Portal, ECommerce Everything) Should I copy porfolio projects and then rewrite them as my own (while still working on my own projects) , just to get to the interview ?
@justinmlawrence
6 ай бұрын
Let’s chat! discord.gg/4hmnhYpfDg
I really don't like that much this kind of interviews, because in real life you have an entire world to explore different approaches to hit the best solution. It feels more stressful than a real scenario, if you ask me. Good questions though. (As feedback: Next time don't use music, most of us are listening our own music)
The interviewer looks like Doctor who
@justinmlawrence
8 ай бұрын
Which one 🤔😅
Great video, is there anyway to try this with you?
@justinmlawrence
10 ай бұрын
Yeah! Just reach out on our Discord. Always looking for new people! 👍🏻 discord.gg/rFP29feQ
Nice video but I think the candidate overall would have failed in my book. 1. They answered all the React questions in the beginning pretty well. 2. The solution for the coding challenge is pretty much O(n^2) due to the includes nested in the for loop. The solution is not optimal and a pretty messy. 3. The react code was messy. The util method should have been brought in from another file instead of residing in the component. The util function itself should have been "pure" and should not include any React state setter methods. That should be done outside of the util method. Not knocking the interviewee at all though, it's a lot harder under pressure obviously.
Not sure I understand how the algorithm challenge has anything to do with react. Seems 90% of time not about react. And the code challenge was not well explained. Thought any consecutive same chars should have been eliminated in the results, but guess I was wrong.
The solution to this is wrong tho. If we had another string for example str = 'ABCDAEFGH' - the longest string here is 'BCDAEFGH'. The solution cody provided wouldn't work , so you need to check with either the substring method or charAt because you need to see if one of the characters is repeated.
@justinmlawrence
3 ай бұрын
Great catch!
Often, one's posture when sitting can reveal their level of expertise or competence.
Instead of using second loop you could use sort method to sort the array from biggest to lowest(arr.sort((a,b) => a.length < b.length ? 1 : -1)) and then return the first element of the array
@nr7343
Жыл бұрын
Sort? Second loop its better bc time complexty Mr russain
@reubz619
Жыл бұрын
Why need to sort the elements when you can just take their length and compare that. Its faster that way!
@lets_see_777
11 ай бұрын
wow you went O(n) to On(logn) complexity and think its better
chale i no reach!
3:56 no, correct answer is callbacks
@techaddictdude
Жыл бұрын
Which question?
@21mighty86
Жыл бұрын
Prop drilling state setter does not fit to react flow of data, and it can cause bugs
really loved watching this, i kept pausing after the question to quickly think about what i would say and how I would write the function before Cody answered. My solution was super similar apart from i used **continue ** in my if block in the loop and at the end to find the longest str in the array i did: return strArr.reduce((longest, current) => { return current.length > longest.length ? current : longest; }, ' ');
also the real complexity is more than n^2, you should consider the usage of string "+=" operator is O(N) itself
"Mid-level" is kind of meaningless in this exact interview.
Terrible React interview. It was an algorithms interview, which he will never need to use.
@cod-the-creator
Жыл бұрын
No joke, the real life correct answer is "dude, Gary, this API is whack, why are you giving me a bunch of bullshit instead of the thing I need?"
@maiaklimenko6614
27 күн бұрын
At least it's close to a real interview. Everyone asks questions about data structure
having a b2 level of english, will be deat on the tree first minute 🤮
Cool video, but so difficult for me to listen to people say "uh" or "um" every other word. haha
bthw in Russia this is definitely not a mid-level it’s more like junior or even intern level of knowledge
@prompt9416
Жыл бұрын
bruhh
@Adidobro
Жыл бұрын
yeah new born baby level, rotting in trench soldier level, what else?
@mikejones8519
Жыл бұрын
In Soviet Ruzzia, code write you!
How is my clever (I guess) solution? #!/bin/env node let longestChunckIndexPair = [0, 0]; let firstIndex = []; const setIfLongest = (lastIndex)=>{ if((lastIndex - firstIndex) > (longestChunckIndexPair[1] - longestChunckIndexPair[0])){ longestChunckIndexPair = [firstIndex, lastIndex]; } } const func = (inputStr)=>{ // O(n-1) for(let i=0; i
@justinmlawrence
11 ай бұрын
Awesome!! 👏🏻
Probably smth like that // 'ABCDDDHIGKL' function longestUniqueSeq(str: string) { let maxStr = ""; let bestMaxStr = ""; for (const ch of str) { if (maxStr.includes(ch)) { bestMaxStr = withMaxLength(bestMaxStr, maxStr); maxStr = ch; continue; } maxStr += ch; } return withMaxLength(bestMaxStr, maxStr); } function withMaxLength(str1: string, str2: string) { return str1.length > str2.length ? str1 : str2; }
FWIW: Big O on this solution 100% O(n^2) because of the `.includes`.
interesting interview! I have a short solution to the algorithm question ```js const longestNonRepeatingSequence = (str) => str .match(/.*?(.)(?=\1|$)/g) .reduce((acc, item) => (item.length > acc.length ? item : acc), ""); ```
const getStr = (s) => { let startSlice = 0; let longestUniqString = " "; const compareAndSetString = (endSlice) => { const newSting = s.slice(startSlice, endSlice); if (longestUniqString?.length longestUniqString = newSting; } }; for (let i = 0; i const currentLetter = s[i]; const nextIndex = i + 1; const nextLetter = s[nextIndex]; if (currentLetter === nextLetter) { compareAndSetString(nextIndex); startSlice = nextIndex; } compareAndSetString(nextIndex); } return longestUniqString; }
My preety solution with reducer. .... Changing the condition to "actualChar === result[0][0]" gives you the second version. const longestUniqueSequention = (str) => { return [...str] .reduce((result, actualChar) => { actualChar a.length .at(0) .reverse() .join(''); } console.log(longestUniqueSequention('ABCDDDDEFGHI')); //
@justinmlawrence
3 ай бұрын
Awesome!! 👏🏻
const getLongest = (str) => { var currStr = ""; var tempStr = ""; for(let i = 0; i if( str[i + 1] && (str[i] != str[i + 1])){ tempStr += str[i]; }else{ if(tempStr.length + 1 > currStr.length){ currStr = tempStr + str[i]; tempStr = ""; } } } return currStr; }