Coding problem · Easy · Basics

Is It a Pangram?

Easy Algorithms & data structures

A pangram contains every letter from a to z at least once (case doesn't matter; other characters are ignored). Return true if s is a pangram.

Example 1

Input: s = "The quick brown fox jumps over the lazy dog"
Output: true

Example 2

Input: s = "Hello world"
Output: false

Hints

Hint 1

Collect the distinct letters you see in a set.

Hint 2

It's a pangram when the set holds 26 letters.

Write and run your solution

Loading the editor… (JavaScript is required to run code in your browser.)

Solution and explanation

Show the solution

Time O(n) · Space O(1)

Add each lower-cased letter to a set and compare its size with 26. Ignore spaces and punctuation.

Reference solution

function isPangram(s) {
  const letters = new Set(s.toLowerCase().replace(/[^a-z]/g, ''));
  return letters.size === 26;
}

Was this page helpful?