Check if the Sentence Is Pangram | 2 Approaches | Snapdeal | Leetcode 1832

  Рет қаралды 7,729

codestorywithMIK

codestorywithMIK

Күн бұрын

This is our 2nd Video on our String Playlist
In this video we will try to solve another interesting Problem : "Check if the Sentence Is Pangram".
Share your learnings on LinkedIn, Twitter (X), Instagram, Facebook(Meta) with the hashtag #codestorywithmik & feel free to tag me.
We will do live coding after explanation and see if we are able to pass all the test cases.
Problem Name : Check if the Sentence Is Pangram
Company Tags : Zoho, Snapdeal
My solutions on Github : github.com/MAZ...
Leetcode Link : leetcode.com/p...
GfG Link : practice.geeks...
My GitHub Repo for interview preparation : github.com/MAZ...
Subscribe to my channel : / @codestorywithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#coding #helpajobseeker #easyrecipes
#interviewpreparation #interview_ds_algo #hinglish

Пікірлер: 31
@rakshapadiyar
@rakshapadiyar Жыл бұрын
keeping a count, to avoid traversing the array again was just so smart!
@Ankitkumar-fz3kc
@Ankitkumar-fz3kc 9 ай бұрын
Leaning new things by each video. Thanks for the count one approach to avoid 2nd traversal of the array.
@codestorywithMIK
@codestorywithMIK 9 ай бұрын
You're very welcome! 😇❤️🙏
@romanraihan9133
@romanraihan9133 Жыл бұрын
bool checkIfPangram(string sentence) { unordered_sets; for(char ch:sentence) s.insert(ch); return s.size() == 26; } I have done this.
@mohsinghazi3574
@mohsinghazi3574 7 ай бұрын
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 };
@jagadeeshp1163
@jagadeeshp1163 Жыл бұрын
freq=[0 for i in range(26)] for i in sentence: freq[ord(i)-ord('a')]+=1 for i in freq: if i
@Codenow10222
@Codenow10222 3 ай бұрын
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
@ubermensch_1111
@ubermensch_1111 7 ай бұрын
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
@arnabsarkar5245
@arnabsarkar5245 29 күн бұрын
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.
@romanraihan9133
@romanraihan9133 Жыл бұрын
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. ?
@codestorywithMIK
@codestorywithMIK Жыл бұрын
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.
@romanraihan9133
@romanraihan9133 Жыл бұрын
@@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 ?
@codestorywithMIK
@codestorywithMIK Жыл бұрын
I see. I just saw the Qn again. You are right. That is definitely a correct approach too.
@romanraihan9133
@romanraihan9133 Жыл бұрын
@@codestorywithMIK Thanks a lot. Get well soon brother.
@anmolbansal4009
@anmolbansal4009 4 ай бұрын
great explanation
@mirdulswarup9065
@mirdulswarup9065 2 жыл бұрын
can you please tell me why we are using the & symbol in for loop
@codestorywithMIK
@codestorywithMIK 2 жыл бұрын
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.
@codestorywithMIK
@codestorywithMIK 2 жыл бұрын
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 &
@mirdulswarup9065
@mirdulswarup9065 2 жыл бұрын
@@codestorywithMIK damn, nobody has told me this before thanks a lot
@codestorywithMIK
@codestorywithMIK 2 жыл бұрын
Glad i could help ❤️❤️❤️
@DevOpskagyaan
@DevOpskagyaan 9 ай бұрын
Done 👍🏻
@thevagabond85yt
@thevagabond85yt 10 ай бұрын
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); }
@SaleemAhmed-f3s
@SaleemAhmed-f3s 3 ай бұрын
what will be time complexity of this solution
@Tanya.1223
@Tanya.1223 Ай бұрын
​@@SaleemAhmed-f3sO(n)
@dhruvrawat7023
@dhruvrawat7023 Жыл бұрын
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; } };
@Movieking011
@Movieking011 Жыл бұрын
Ascii Value of 'a' is 97
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you so much Shivanshu for this keen observation. I have added corrections captions there. Thanks again ❤️❤️
@jyothipallapure-bu9ux
@jyothipallapure-bu9ux 5 ай бұрын
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 .
@codestorywithMIK
@codestorywithMIK 5 ай бұрын
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.
@codeandtalk6
@codeandtalk6 9 ай бұрын
❤❤❤❤
@bhartendupant8859
@bhartendupant8859 9 ай бұрын
Count and Say | Made Super Easy | Google | Explanation | Live Coding
16:28
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 2,6 МЛН
How I Failed the Google Coding Interview (and lessons I learned)
14:24
How I Tricked My Brain to Be Addicted to Coding (The Dopamine Hack)
8:06
Ashish Pratap Singh
Рет қаралды 100 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 577 М.
ASHNEER GROVER GOT ROASTED BY SALMAN KHAN!
13:08
Thugesh Unfiltered
Рет қаралды 1 МЛН
LeetCode 1832: Check if the Sentence Is Pangram Solution
6:30
Engineering Digest
Рет қаралды 2,3 М.
I FAILED 30+ Coding Interviews Until I Learned THIS
9:16
Ashish Pratap Singh
Рет қаралды 43 М.
Java Program to check given String is Panagram or not?
8:24
Learn With KrishnaSandeep
Рет қаралды 59 М.
How To Pass Technical Interviews When You Suck At LeetCode
14:32
How I Approach a New Leetcode Problem (live problem solving)
25:31
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН