L1 · FoundationsText basics~2 min · 4 tests

Check If a Sentence Is a Pangram

Check whether a sentence uses every letter of the alphabet at least once with a set in O(n). Includes early exit and case handling. Python practice.

The problem

Return True if sentence contains every letter a–z at least once (ignoring case).

Examples

  1. Example 1

    Input

    is_pangram('The quick brown fox jumps over the lazy dog')

    Expected output

    True
  2. Example 2

    Input

    is_pangram('Hello world')

    Expected output

    False

+ 2 hidden tests on Submit.

Edge cases to ask about

  • Upper case
  • Punctuation
  • Empty

Hints

0/3

    How an interviewer scores this

    0/9
    Python 3.13 · is_pangram
    ⌘/Ctrl + Enter runs the examples

    Your code runs in real CPython inside your browser — nothing is sent anywhere. The first run downloads the interpreter (about 6 MB, once). Your code is saved on this device as you type.

    Complexity Lab

    What does this cost as n grows?

    Interviewers score the analysis as much as the code. Commit to an answer first — then check it, and read why.

    Time complexity of the optimal solution
    Space complexity (extra memory)

    Pick both to reveal the answer.

    From brute force to optimal

    The progression an interviewer wants to hear, one step at a time.

    ApproachTimeSpaceIdea
    Check each letter with `in`O(26 · n)O(1)
    bestSet subset testO(n)O(1)At most 26 + charset entries.
    Walkthrough of the optimal approach (try it yourself first)

    Lower-case the sentence, make a set of its characters, and check the alphabet is a subset (<=). The set can hold at most a few dozen distinct characters, so its space is O(1) even for a huge sentence.

    Complexity: O(n) time, O(1) space. One pass to build the set; the set is bounded by the character set size, not by n.

    Reveal the reference solution
    import string
    
    def is_pangram(sentence):
        return set(string.ascii_lowercase) <= set(sentence.lower())

    Follow-ups interviewers ask

    • Return the missing letters.

    Frequently asked interview questions

    Core interview concepts, complexities, and follow-ups scored by hiring teams.

    What is the time complexity of Check If a Sentence Is a Pangram in Python?

    The optimal solution runs in O(n) time and O(1) auxiliary space. One pass to build the set; the set is bounded by the character set size, not by n.

    What is the brute-force approach, and how do you optimise it?

    Check each letter with `in`: O(26 · n) time, O(1) space. Set subset test: O(n) time, O(1) space. At most 26 + charset entries.

    What follow-up questions do interviewers ask about Check If a Sentence Is a Pangram?

    Return the missing letters.