HackerRank ‘Pangrams’ Solution

Short Problem Definition:

Roy wanted to increase his typing speed for programming contests. So, his friend advised him to type the sentence “The quick brown fox jumps over the lazy dog” repeatedly, because it is a pangram. (Pangrams are sentences constructed by using every letter of the alphabet at least once.)

Link

Pangrams

Complexity:

time complexity is O(N)

space complexity is O(N)

Execution:

There are 26 letters in the English alphabet. A sentence is a pangram, if it contains all 26 characters.

Solution:
#!/usr/bin/py

def getCharCnt(s):
    return len(set(c.lower() for c in s if c != ' '))

if __name__ == '__main__':
    s = raw_input()
    if getCharCnt(s) == 26:
        print "pangram"
    else:
        print "not pangram"

If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.

Facebooktwittergoogle_plusredditpinterestlinkedin