Count Distinct Letters
Easy About 8 min Free, no account needed
How many different letters appear? A 26-slot array already knows.
The brief
Given text, count the distinct English letters present,
case-insensitive (the answer is between 0 and 26).
Lower-casing the whole document (and LINQ chains over it) allocate copies and iterator machinery. The hidden test is a 100 KB document under a 32 KB allocation budget, so watch your allocations: a copy of the document alone blows it.
Starter code
using System;
public class Solution
{
// TODO: return the number of distinct English letters, case-insensitive.
public int CountDistinctLetters(string text)
{
throw new NotImplementedException();
}
}How it is graded
Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.
What it practices
- Hash maps and sets
- Trade memory for constant-time lookups, membership tests and frequency counts.
- String processing
- Parse, scan and match text character by character with correct edge cases.
Related katas
- Isomorphic Strings Easy Free Can one string be turned into the other by a consistent character substitution?
- Add Binary Strings Easy Free Add two binary numbers far too long for any built-in integer.
- Maximum Bracket Depth Easy Free How deep do the parentheses nest? A counter beats a stack.
- Base64 Decoded Length Easy Free The decoded size is pure arithmetic - no need to decode.