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

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 พ.ย. 2024

ความคิดเห็น • 31

  • @rakshapadiyar
    @rakshapadiyar ปีที่แล้ว +6

    keeping a count, to avoid traversing the array again was just so smart!

  • @Ankitkumar-fz3kc
    @Ankitkumar-fz3kc 9 หลายเดือนก่อน +1

    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 ปีที่แล้ว +4

    bool checkIfPangram(string sentence) {
    unordered_sets;
    for(char ch:sentence) s.insert(ch);
    return s.size() == 26;
    }
    I have done this.

  • @romanraihan9133
    @romanraihan9133 ปีที่แล้ว +2

    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 ปีที่แล้ว +2

      @@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  ปีที่แล้ว +2

      I see. I just saw the Qn again. You are right. That is definitely a correct approach too.

    • @romanraihan9133
      @romanraihan9133 ปีที่แล้ว +2

      @@codestorywithMIK Thanks a lot. Get well soon brother.

  • @Codenow10222
    @Codenow10222 3 หลายเดือนก่อน +1

    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 6 หลายเดือนก่อน +1

    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

  • @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
    };

  • @mirdulswarup9065
    @mirdulswarup9065 2 ปีที่แล้ว +4

    can you please tell me why we are using the & symbol in for loop

    • @codestorywithMIK
      @codestorywithMIK  2 ปีที่แล้ว +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 ปีที่แล้ว +4

      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 ปีที่แล้ว +1

      @@codestorywithMIK damn, nobody has told me this before thanks a lot

    • @codestorywithMIK
      @codestorywithMIK  2 ปีที่แล้ว +2

      Glad i could help ❤️❤️❤️

  • @anmolbansal4009
    @anmolbansal4009 3 หลายเดือนก่อน

    great explanation

  • @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

  • @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;
    }
    };

  • @arnabsarkar5245
    @arnabsarkar5245 18 วันที่ผ่านมา

    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.

  • @DevOpskagyaan
    @DevOpskagyaan 9 หลายเดือนก่อน +1

    Done 👍🏻

  • @thevagabond85yt
    @thevagabond85yt 10 หลายเดือนก่อน +1

    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 2 หลายเดือนก่อน

      what will be time complexity of this solution

    • @Tanya.1223
      @Tanya.1223 29 วันที่ผ่านมา

      ​@@SaleemAhmed-f3sO(n)

  • @Movieking011
    @Movieking011 ปีที่แล้ว +3

    Ascii Value of 'a' is 97

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +2

      Thank you so much Shivanshu for this keen observation. I have added corrections captions there.
      Thanks again ❤️❤️

  • @jyothipallapure-bu9ux
    @jyothipallapure-bu9ux 5 หลายเดือนก่อน +1

    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 หลายเดือนก่อน