Technical Questions and Answers React Fundamentals: State vs. Context: Explained the difference between state and context in React. State Updates: Discussed how to trigger state changes in parent components from child components. Redux: Shared thoughts on Redux and its boilerplate nature. Component Passing: Explained how to pass components as props to other components. Coding Exercise: Longest Substring.
another way function getIterateData(str, list) { let filterChar = list ?? "ABCDDDEFGHI"; let filterStr = Array.from(filterChar.split(" ")[0]); let pos = filterChar.indexOf(str) + str.length; let strVal = []; let center = Math.floor((filterChar.length - 1) / 2); let uniqueValue; if (pos <= center) { for (let i = 1; i <= filterChar.length; i++) { if (i > str.length) { if ( strVal.includes(filterStr[i]) === false && filterStr[i] != undefined ) { strVal.push(filterStr[i]); } } } uniqueValue = strVal.join(""); } else { uniqueValue = filterChar.slice(0, filterChar.length - str.length); } return uniqueValue; } console.log(getIterateData("FGHI", "ABCDDDDEFGHI"));
I'm not sure, is there is any for JS, but I'd use there two set data structure - the first one is currentLongestUniqSequence and the other is literralylongestUniqSequence. Then iterating through input string, check if currentLongestUniqSequence contains current one charater. If its not, add it, otherwise compare the legth of both sets and if current greater, replace the longest with a current. I did it on C# and works good. Code: public static string GetLongestUniqCharacterSequence(string source) { var currentUniqSequence = new HashSet<char>(); var longestUniqSequence = new HashSet<char>(); for(var i = 0; i < source.Length; ++i) { if (currentUniqSequence.Contains(source[i])) { if (currentUniqSequence.Count > longestUniqSequence.Count) { longestUniqSequence = currentUniqSequence; } currentUniqSequence = new(); continue; } currentUniqSequence.Add(source[i]); } if (currentUniqSequence.Count > longestUniqSequence.Count) { longestUniqSequence = currentUniqSequence; } var sb = new StringBuilder(); foreach (var ch in longestUniqSequence) { sb.Append(ch); } return sb.ToString(); }
const getLongestNonRepeatingSubstring = (s) => { let result = "" for (let i = 0; i < s.length; i++) { let char = s[i]; let newString = s.substring(0, i) if (!newString.includes(char)) { result += char } } return result }
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; }, ' ');
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.
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...".
Around 1:01:30 Justin seems to justify the usage of a "tricky" problem such as LeetCode 6. ZigZag Conversation for the sake of "seeing how an interviewee approaches a problem" or just to "weed out candidates." I think that this an extremely poor way of interviewing a people. What exactly are we testing for here with a problem that doesn't utilize a recognized algorithm like sorting or searching and isn't directly applicable to many use cases in production? Are we testing for pattern matching or the ability to simulate the physical layout or structure? Unless the applicant was applying for a job where they would be doing game development, implementing some sort of rendering algorithm or doing complex data processing and formatting asking a candidate this type of question is at best an exercise in pointless problem solving. At worst it's emotional and intellectual hazing or waterboarding that doesn't bring out the best in candidates. It says a lot of a company and the engineering culture if the interviewer busts this question out during a front end interview: cut your losses and apply somewhere else.
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?
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.
Another great vid, Justin!. What seems like such a simple algo is nothing but. Your solution is so eloquent. Mine not so much, but would love your feedback on it when you have some time. const replaceLongestZeros = (s) => { const hm = {} for (let i = 0; i < s.length; i++) { if (s[i] === '0') { if (!hm[i]) { hm[i] = { stidx: i, enidx: i } } if (hm[i-1]) { hm[i] = { ...hm[i-1], enidx: hm[i-1].enidx + 1 } } } } let stidx = 0, enidx = 0 for (const i in hm) { if (hm[i].enidx - hm[i].stidx >= enidx - stidx) { stidx = hm[i].stidx enidx = hm[i].enidx } } return [...s].map((x, idx) => idx >= stidx && idx <= enidx ? '#' : x).join('') }
Love your videos! Your solutions to these nasty algos are sublime. Just a mention but you could have just used flat().join('') instead of reduce. Keep em coming!
const charCountMap = {}; str.split().forEach((char) => { charCountMap[char] = charCountMap[char] + 1; }) let mostUsedCharKey; Object.keys(charCountMap).forEach((key) => { if (!mostUsedCharKey) { mostUsedCharKey = key; return; } if (charCountMap[mostUsedCharKey] > charCountMap[key]) return; mostUsedCharKey = key; }) return charCountMap[mostUsedCharKey] I'm sure that there is a better way to do this but I have not looked anywhere so this is my best. Complexity kind of O(n*2) I guess.
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.
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.
This should work in python def uniqueWords(wordsList): hashMap = {} counter = 0 for words in wordsList: for idx in range(len(words)): currentWord = words[idx] if currentWord not in hashMap: hashMap[currentWord] = counter else: if hashMap[currentWord] != counter: del hashMap[currentWord] counter += 1 return list(hashMap.keys()) print(uniqueWords([["hello", "goodbye", "morning", "hello"], ["goodbye", "night"]])) Should return ['hello', 'morning', 'night']
So I think this same problem is on leetcode and it's called Longest Substring Without Repeating Characters. The leetcode problem wants you to return the number of repeating characeters instead of retuning the the actual letters. For this problem you wanna use a sliding window approach. The way it works is that you would want to have a window of charaters and the moment you run into a character you have seen before, you want to shrink your window until it fits your constraint of no repeating characters. I will share the python code below which should be fairly easy to understand. This will return the length instead of the actual characters. def lengthOfLongestSubstring(self, s: str) -> int: left = 0 right = 0 maxSub = 0 visited = set() end = len(s) - 1 while right < len(s): current = s[right] while current in visited: visited.remove(s[left]) left += 1 visited.add(current) right += 1 maxSub = max(maxSub, right - left) return maxSub
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 ?
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!
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! 😂
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 < currentSubstring.length) { longestSubstring = currentSubstring; } } return longestSubstring; }