0% completed
Valid solution without using a hashmap
Nabeel Keblawi
Sep 4, 2024
What I did was first convert the sentence to lower case, then declared an alphabet string to loop through it and search for each character in the sentence.
Since we're looking for pangrams that have ALL the letters in the alphabet, if the "char not in sentence_lower" is ever found true, then abort the function by returning False. If the loop completes without executing the conditional block, then return True.
More than one way to skin a cat...
class Solution: def checkIfPangram(self, sentence): sentence_lower = sentence.lower() alphabet = "abcdefghijklmnopqrstuvwxyz" for char in alphabet: if char not in sentence_lower: return False return True
1
0
Comments
Nabeel Keblawia year ago
This is O(n) for both time and space complexity, btw
Ashaun Thomasa year ago
Straightforward solution
Elan Utta5 days ago
This is not O(n), the in has a time complexity of Big O (N), and since we already pass for each character on the string, the time complexity of this algorithm is Big O n square.
On this page
Problem Statement
Solution
Code
Time Complexity
Space Complexity
Conclusion