Sponsored
Sponsored
This approach leverages a set data structure to track the unique characters. The idea is to iterate through the sentence and add each letter to a set. Finally, we check if the size of the set is 26, which indicates that all letters of the alphabet are present.
Time Complexity: O(n), where n is the length of the sentence.
Space Complexity: O(1), since we use a fixed-size array of 26.
1function checkIfPangram(sentence) {
2 const seen = new Set(sentence);
3 return seen.size === 26;
4}
5
In JavaScript, the Set object is utilized to eliminate duplicate characters and track which letters appear in the sentence. A size of 26 means the sentence is a pangram.
This method uses a boolean array of size 26 to directly map each alphabet character to an index. By iterating over each character in the sentence, we update its corresponding index in the array to true. The sentence is confirmed as a pangram if all indices in the boolean array are true.
Time Complexity: O(n), with n denoting sentence length; we check each letter.
Space Complexity: O(1), constant size boolean array.
1
The Python application applies a list of integers, functioning similarly to a boolean array. Every encountered letter activates its corresponding index. The sum of the list after traversal will determine the pangram requirement.