Pangrams

Sort by

recency

|

229 Discussions

|

  • + 0 comments

    C#

    public static string pangrams(string s)
        {
            string newString = s.ToLower();
            
            string result = "pangram";
            
            for(char letra = 'A'; letra <= 'Z'; letra++){
                if(!newString.Contains(char.ToLower(letra))) {
                    result = "not "+result;
                    break;
                }
            }
            
            return result;
        }
    
  • + 0 comments
    	Set<Character> chars = new HashSet<>();
            for (int i='a'; i<='z'; i++) {
                chars.add((char)i);
            }
            for (char c : s.toCharArray()) {
                if (c == ' ') continue;
                if (c >= 'A' && c <= 'Z') {
                    chars.remove((char)(c+32));
                } else {
                    chars.remove(c);
                }
            }
            return chars.size() == 0 ? "pangram" : "not pangram";
    
  • + 0 comments

    Python3 Solution: def pangrams(s): string = s.lower() for j in [chr(i) for i in range(ord('a'), ord('z') + 1)]: if j not in string: return('not pangram')

    return('pangram')
    
  • + 0 comments

    Rust 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

    pub fn pangrams(s: &str) -> String {
        //Time complexity: O(n)
        //Space complexity (ignoring input): O(1)
        let mut bit_mask = 0;
        for letter in s.to_lowercase().chars() {
            if ('a'..='z').contains(&letter) {
            let bit_pos = letter as u32 - 'a' as u32;
            bit_mask |= 1 << bit_pos;
            };
        }
        if bit_mask == (1 << 26) - 1 {
            return "pangram".to_string();
        };
    
        "not pangram".to_string()
    }
    
  • + 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"