Coding Interview Training #1 - String Processing

preview_player
Показать описание
Today's interview problem is: "Given a string, find whether it contains unique characters only"

---
Рекомендации по теме
Комментарии
Автор

Very, very nice video ! Hope to see more of this format !

LiorCHAMLA
Автор

Thanks! I wouldn't think about the sort to optimize the unique method, it's very clever.

alexer
Автор

Very interesting video! I took few minutes to test and find a solution by myself. It was more instructive to watch the coding interview!
I can't wait to see new episodes!

tomdafiz
Автор

Awesome video. This a simple example that allows everyone to understand and learn as well as make more noticeable other aspects of coding like non-being afraid to have mistakes, clarifying requirements, testing and debugging.

richardpb
Автор

I could never lol. But this is legend. A+ content ya'll. Loved this walkthrough and looking forward to more of these. I'm absolutely going to obliterate the like button.

derickmoncado
Автор

Very nice video, learned a lot, thanks!

alexsoyes
Автор

1. Code should check the length of the string before converting it to lowercase.
2. Code does not need to convert the whole string to lowercase because it can convert to the lowercase only character to test

valery
Автор

2 remarks:
- ASCII code takes only 7 bits but I think you talked about strings with 8 bits by chars
- we can also replace map by vector (table) of 128 (or 256) elements. I think it's a little bit more optimized than a map

I don't know Javascript maps, but I suppose that implementation keeps insertion order which is useless on our case. Only an ad-hoc hashmap (size and key) will be equivalent to the vector.

antoinejulien
Автор

I'm not an expert in JS, but wouldn't the Map algorithm add an overhead that would not be compensated by the better complexity for such small inputs?

Krimog
Автор

may be compare [new set(str.split(""))].length > str.length

adoumbia
Автор

Please consider this solution :
function hasUniqueOnly(str) {
const lowerStr = str.toLowerCase();
if (lowerStr.length == new Set(lowerStr).size){return true;}
return false;
}

fredericlocquet
Автор

Is it Ok to check the documentation during the interview?

joneswafula
Автор

Very nice video !!! 🤩🤩🤩

In C++, the solution could be something like this:

#include <bits/stdc++.h>
using namespace std;

bool hasUniqueOnly(string &s){
if(s.length() > 256){
return false;
}
unordered_set<unsigned char> ust;
for(auto &c: s){

return false;
}
ust.insert(tolower(c));
}
return true;
}

int main(){

vector<string> test_case = {"ABCDEF", "ABCFDEF", "ABCaDEF", "aBCDEF", "/BCDEF", "/BCDEF/"};
for(auto &x: test_case){
cout << (hasUniqueOnly(x)==1 ? "true":"false") << endl;
}
return 0;
}

It is not quite optimal, but should do.

hekiganroku
Автор

Ugh, if you're really interested in performance, you do not create and destroy objects in functions. It's thread safe this way, but DOG slow.

JohnHoffmanPhd
Автор

I would go something like `new but performance geeks probably would kill me.

case differences;
new

tinmank