Interviewing for Front-End Engineers Removing Duplicate Strings Exercise
Transcript from the "Removing Duplicate Strings Exercise" Lesson
>> All right, next problem. I've got this problem with duplicate strings. I've got too many strings. So what I need you to do is create a function that takes a string, returns a new string with duplicates remove. So my test case for this is a test string. And I want you to create a function that takes in a string and just removes all the duplicates.
[00:00:25] So it should return this is a test string, or something along those lines. And this one is a little trickier, so I'll say ten minutes on this one. And remember those methods we used earlier, they'll be really helpful here.
>> So questions, is this only for words that are the same that are next to each other?
[00:00:44] Or if there was another is in that sentence, it should remove two of them and just leave one?
>> Great question. Yes, that's a great question you would ask. Yes, it doesn't matter what the position is. It should only have one unique value. In fact I would call this unique values or duplicate strings.
[00:01:02] So I could do the same thing with numbers if I wanted to kind of give it a way too much, yes?
>> Capitalization matters like uppercase this and lowercase this, would they be the same string or would they be too unique?
>> Good question, I'm gonna say they're unique but in terms of solving this I wouldn't care as much.
[00:01:20] But I love that question that means you're already thinking ahead, yes?
>> Can you always remove the first occurrence of the duplicate or do you leave the first occurrence and remove the things after that?
>> Great question, it doesn't matter. This one is more of an open ended-
>> This one it doesn't matter I guess.
>> Yeah, this is more of an open ended question. And I'll say this, in general the interviewer probably is gonna give you test cases. They'll just say create a function that takes string and returns a new string with duplicates removed.
[00:01:48] I'm giving you test cases because I'm a nice person, but if you're on a whiteboard, they're probably not gonna do that for you.