Encrypt and Decrypt Strings | Leetcode 2227 | Range Based Binary Search | Contest 287 🔥🔥

preview_player
Показать описание
Here is the solution to "Maximum Candies Allocated to K Children" leetcode question. Hope you have a great time going through it.

🔥🔥🔥🔥👇👇👇 For discussion/feedback/humour/doubts/new openings

🔴 Checkout the series: 🔥🔥🔥

🔥🔥🔥 Leetcode Monthly Contest Playlist

PS : Please increase the speed to 1.25X
Рекомендации по теме
Комментарии
Автор

Nice explanation sir, , simply amazing

AYUSHKUMAR-eoxi
Автор

Great explanation Sunchit!! got messy in the presentation part awsome intuition xD

techyguy
Автор

Hi All, I solved this problem using Trie data structure and it takes about 1000ms in JAVA to submit. Later I realized that fastest solution is same as described this video. Many people submitted their first solution based on Trie then later on realized that It can be done using Maps only.

cwmayank
Автор

map<char, string>mp1;
map<string, int>mp2;
Encrypter(vector<char>& keys, vector<string>& values, vector<string>& dictionary) {
int n=keys.size();
for(int i=0;i<n;i++)
mp1[keys[i]]=values[i];

for(int i=0;i<dictionary.size();i++)
{
string ans=encrypt(dictionary[i]);
mp2[ans]++;

}


}

string encrypt(string word1) {
int n=word1.length();
string ans="";
for(int i=0;i<n;i++)
{
ans+=mp1[word1[i]];
}
return ans;
}

int decrypt(string word2) {
if(mp2.count(word2))
return mp2[word2];
return 0;
}
cpp me galat kyu aa rha hai

ecepranaykumar
Автор

Code shown in video will fail for be test case -
["Encrypter", "decrypt"]
[[["a"], ["pq"], ["aa", "x"]], ["null"]]
As new test cases are added to this problem now. Just try to handle the case when character does not exist in encryptionMap.

cwmayank
join shbcf.ru