you were solving this question on leetcode and today i did the same solution as yours which beats only 20% in both time an space , best solution would be: int arr[26]={0}; for(int i=0;i
No, because with tree there will be cache miss, but with array as the size is 26 it is possible that once it will load the entire array in cache and wound never go back to RAM.
I think your algorithm will continue checking for the whole string(lets say length is 10000000) and what will happen if the first 26 elements will already have A-Z ? then we keep on checking the rest of string? i think it might be unnecessary. I would prefer vector to be int rather than bool and for every first time we encounter new letter I will increment counter and when counter reaches 26 i will return true. if not false.
This should work with very big string, but I doubt also because we would need two extra things, increment and if check. So in average it might slow down also. But not sure, we should check. Because the worst case might be like we have all A from beginning and in the end B - Z then we have to pay very big penalty.
Sir this is simplist that anyone has explain all salo auro ko khud nhi pta ky bol rhe hai really thank you appreciate❤😊
you were solving this question on leetcode and today i did the same solution as yours which beats only 20% in both time an space ,
best solution would be:
int arr[26]={0};
for(int i=0;i
What if you do :
std::map myMap;
for each character {
myMap[e] = true;
}
return myMap.Size() == 26
Is it faster ?
No, because with tree there will be cache miss, but with array as the size is 26 it is possible that once it will load the entire array in cache and wound never go back to RAM.
My psudo solution:
unordered_set tset;
for(const auto& ch : input_str){
tset.insert(tolower(ch));
return true if tset.size()==26;
}
return false;
I think your algorithm will continue checking for the whole string(lets say length is 10000000) and what will happen if the first 26 elements will already have A-Z ? then we keep on checking the rest of string? i think it might be unnecessary. I would prefer vector to be int rather than bool and for every first time we encounter new letter I will increment counter and when counter reaches 26 i will return true. if not false.
This should work with very big string, but I doubt also because we would need two extra things, increment and if check. So in average it might slow down also.
But not sure, we should check.
Because the worst case might be like we have all A from beginning and in the end B - Z then we have to pay very big penalty.
👍
👍