Pangrams

  • + 0 comments

    Python best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

    def pangrams(s: str):
        # Time complexity: O(n)
        # Space complexity (ignoring input): O(1)
        bit_mask = 0
        for letter in s.lower():
            if (letter <= "z") and (letter >= "a"):
                bit_pos = ord(letter) - ord("a")
                bit_mask |= 1 << bit_pos
    
        if bit_mask == (1 << 26) - 1:
            return "pangram"
        return "not pangram"
    
    
    def pangrams_not_elegant(s: str):
        # Time complexity: O(n)
        # Space complexity (ignoring input): O(1)
        dict_letters = {}
        for letter in s.lower():
            if (letter <= "z") and (letter >= "a") and (letter not in dict_letters):
                dict_letters[letter] = 1
    
        if len(dict_letters) == 26:
            return "pangram"
    
        return "not pangram"