881884. Pangram check

Basic

Pangram Check

Summary

A pangram is a sentence that uses all the letters of the alphabet at least once. This problem involves checking whether a given string is a pangram or not. The solution requires using the Standard Template Library (STL) in C++.

Detailed Explanation

To solve this problem, we can start by iterating over each character in the input string. For each character, we check if it's present in the alphabet. If it is, we mark it as used. At the end of the iteration, we check if all characters in the alphabet have been marked as used. If they have, then the original string is a pangram.

Here's a step-by-step breakdown of the solution:

  1. Create an array to store the usage status of each character (0 for not used, 1 for used).
  2. Iterate over each character in the input string.
  3. For each character, check if it's present in the alphabet and update the corresponding entry in the array.
  4. After iterating over all characters, check if all entries in the array are marked as used (i.e., 1). If they are, then the original string is a pangram.

Here's an ASCII art diagram to illustrate this:

     +---------------+
     |  Used Array  |
     +---------------+
     |  A: 0  B: 0  C: 0 ... X: 0 Y: 0 Z: 0  |
     +---------------+
       ...

In the above diagram, each row represents a character in the alphabet. Initially, all characters are marked as not used (0). As we iterate over the input string and mark characters as used, the corresponding entries will be updated to 1.

Time complexity: O(n), where n is the length of the input string. Space complexity: O(1), since we only need a fixed-size array to store the usage status of each character.

Optimized Solutions

Java

View on GeeksforGeeks
import java.util.Arrays;

public class PangramChecker {
    public static boolean isPangram(String s) {
        String alphabet = "abcdefghijklmnopqrstuvwxyz";
        int[] usedArray = new int[26];

        for (char c : s.toLowerCase().toCharArray()) {
            if (alphabet.indexOf(c) != -1) {
                usedArray[c - 'a']++;
            }
        }

        return Arrays.stream(usedArray).allMatch(i -> i == 1);
    }
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.