Skip to main content
Made it work for uppercase letters too...
Source Link

Just playing Devil's advocate because I didn't like the O(n lg n) time for this...

string pangramInput = Console.ReadLine().ToLower();
var alphabet = Enumerable.Range(97, 26).Select((x) => (char)x);
var pc = pangramInput.Select((c, i) => new{val = c, idx = i})
                     .GroupBy(x => x.val, x=>x.idx)
                     .ToDictionary(k => k.Key, v => v);
var pangramCheck = alphabet.All(v => pc.ContainsKey(v));
string answer = pangramCheck ? "pangram" : "not pangram";
Console.WriteLine(answer);

From a performance standpoint, this might be much better. Not only is it O(n), but I think this uses laziness a little more and allows for non-alphabets.

Looking at just the Linq, I suppose both of these work as well. Yours might be a little more readable.

Just playing Devil's advocate because I didn't like the O(n lg n) time for this...

string pangramInput = Console.ReadLine();
var alphabet = Enumerable.Range(97, 26).Select((x) => (char)x);
var pc = pangramInput.Select((c, i) => new{val = c, idx = i})
                     .GroupBy(x => x.val, x=>x.idx)
                     .ToDictionary(k => k.Key, v => v);
var pangramCheck = alphabet.All(v => pc.ContainsKey(v));
string answer = pangramCheck ? "pangram" : "not pangram";
Console.WriteLine(answer);

From a performance standpoint, this might be much better. Not only is it O(n), but I think this uses laziness a little more and allows for non-alphabets.

Looking at just the Linq, I suppose both of these work as well. Yours might be a little more readable.

Just playing Devil's advocate because I didn't like the O(n lg n) time for this...

string pangramInput = Console.ReadLine().ToLower();
var alphabet = Enumerable.Range(97, 26).Select((x) => (char)x);
var pc = pangramInput.Select((c, i) => new{val = c, idx = i})
                     .GroupBy(x => x.val, x=>x.idx)
                     .ToDictionary(k => k.Key, v => v);
var pangramCheck = alphabet.All(v => pc.ContainsKey(v));
string answer = pangramCheck ? "pangram" : "not pangram";
Console.WriteLine(answer);

From a performance standpoint, this might be much better. Not only is it O(n), but I think this uses laziness a little more and allows for non-alphabets.

Looking at just the Linq, I suppose both of these work as well. Yours might be a little more readable.

Source Link

Just playing Devil's advocate because I didn't like the O(n lg n) time for this...

string pangramInput = Console.ReadLine();
var alphabet = Enumerable.Range(97, 26).Select((x) => (char)x);
var pc = pangramInput.Select((c, i) => new{val = c, idx = i})
                     .GroupBy(x => x.val, x=>x.idx)
                     .ToDictionary(k => k.Key, v => v);
var pangramCheck = alphabet.All(v => pc.ContainsKey(v));
string answer = pangramCheck ? "pangram" : "not pangram";
Console.WriteLine(answer);

From a performance standpoint, this might be much better. Not only is it O(n), but I think this uses laziness a little more and allows for non-alphabets.

Looking at just the Linq, I suppose both of these work as well. Yours might be a little more readable.