But what if the sentence is as follows = “aabcdefghijklmnopqrstuvwxyz” When you insert each char in set, the size of set will be 26 because it will contain only unique elements. And hence the duplicate ’a’ in your sentence will be missed.
@@codestorywithMIK But is that actually matters ? I need to check if there are all 26 letters are present or not. do we need to count how many times which letters occur or not ?
the video solution takes O(n) time complexity More optimized ✅👇 // Time complexity = O(1) // Space complexity = O(1) class Solution { public: bool checkIfPangram(string sentence) { int n = sentence.size() ; if(n
Respect for your efforts 💖 and thanks for creating this channel...... this problem is easily solvable by set => class Solution { public: bool checkIfPangram(string sentence) { set st; for(int i=0; i
Coming to your Qn. Using & operator helps to have the address of the variable and no copy of the variable is made internally by the compiler. Which improves the performance of the code. In short, to avoid COPY, we use &
Another optimization can be done bhaiya. First find the length of the string. If the length itself is less than 26, then we will return false then and there.
One question: Count will addon if it found new character but what if repeatation of character occur.at that time also count will increase.and at that time if 26 characters occurs with repeatation then in that case also it work. But actually it is wrong na . Please do explain this case. Iam wondering how all test cases passed ? Pov:In question it is mentioned that repeatation also occur .
As per the problem statement, Pangram means all characters must occur atleast once. It meana, a character can occur more than once. The important criterion is that all characters must be present.
keeping a count, to avoid traversing the array again was just so smart!
Leaning new things by each video. Thanks for the count one approach to avoid 2nd traversal of the array.
You're very welcome! 😇❤️🙏
bool checkIfPangram(string sentence) {
unordered_sets;
for(char ch:sentence) s.insert(ch);
return s.size() == 26;
}
I have done this.
what if we take an unordered_sets , and inset the chars into that set. and simply return the size of the set is 26 or not. ?
But what if the sentence is as follows = “aabcdefghijklmnopqrstuvwxyz”
When you insert each char in set, the size of set will be 26 because it will contain only unique elements. And hence the duplicate ’a’ in your sentence will be missed.
@@codestorywithMIK But is that actually matters ? I need to check if there are all 26 letters are present or not. do we need to count how many times which letters occur or not ?
I see. I just saw the Qn again. You are right. That is definitely a correct approach too.
@@codestorywithMIK Thanks a lot. Get well soon brother.
the video solution takes O(n) time complexity
More optimized ✅👇
// Time complexity = O(1)
// Space complexity = O(1)
class Solution {
public:
bool checkIfPangram(string sentence) {
int n = sentence.size() ;
if(n
Respect for your efforts 💖 and thanks for creating this channel......
this problem is easily solvable by set =>
class Solution {
public:
bool checkIfPangram(string sentence) {
set st;
for(int i=0; i
function checkIfPangram(sentence: string): boolean {
let alphabetSet = new Set()
for(let i = 0; i< sentence.length; i++){
alphabetSet.add(sentence[i])
}
return alphabetSet.size === 26
};
can you please tell me why we are using the & symbol in for loop
Hi Mirdul, first of all sorry for late reply. As I mentioned due to some restriction Settings I couldn’t see any comment. Today i am replying to all.
Coming to your Qn. Using & operator helps to have the address of the variable and no copy of the variable is made internally by the compiler. Which improves the performance of the code.
In short, to avoid COPY, we use &
@@codestorywithMIK damn, nobody has told me this before thanks a lot
Glad i could help ❤️❤️❤️
great explanation
freq=[0 for i in range(26)]
for i in sentence:
freq[ord(i)-ord('a')]+=1
for i in freq:
if i
class Solution {
public:
bool checkIfPangram(string sentence) {
vector alphabet(26, false);
for(char& c: sentence){
alphabet[c - 'a'] = true;
}
for(bool present: alphabet){
if(present == false){
return false;
}
}
return true;
}
};
Another optimization can be done bhaiya. First find the length of the string. If the length itself is less than 26, then we will return false then and there.
Done 👍🏻
1 line Java
return sentence.chars()
.filter(Character::isAlphabetic)
.distinct()
.count() == 26;
Java using Stream : 3 lines.
public boolean checkIfPangram(String sentence) {
int [] alphabets = new int[26]; //java initialized int array with 0
sentence.chars().forEach(c->alphabets[c-'a']=1);
return (Arrays.stream(alphabets).asLongStream().sum()==26);
}
what will be time complexity of this solution
@@SaleemAhmed-f3sO(n)
Ascii Value of 'a' is 97
Thank you so much Shivanshu for this keen observation. I have added corrections captions there.
Thanks again ❤️❤️
One question:
Count will addon if it found new character but what if repeatation of character occur.at that time also count will increase.and at that time if 26 characters occurs with repeatation then in that case also it work. But actually it is wrong na .
Please do explain this case.
Iam wondering how all test cases passed ?
Pov:In question it is mentioned that repeatation also occur .
As per the problem statement, Pangram means all characters must occur atleast once.
It meana, a character can occur more than once. The important criterion is that all characters must be present.
❤❤❤❤
❤