Skip to content

Pangram Check

Problem Description

Given a sentence represented as an array A of strings that contains all lowercase alphabets.

Chech if it is a pangram or not.

A pangram is a unique sentence in which every letter of the lowercase alphabet is used at least once.

Problem Constraints

1 <= |A| <= 10^5
1 <= |Ai|<= 5
1 <= |A| <= 10^5
1 <= |Ai|<= 5

Input Format

Given an array of strings A.
Given an array of strings A.

Output Format

Return an integer.
Return an integer.

Example Input

Input 1:
A = ["the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"]

Input 2:
A = ["bit", "scale"]
Input 1:
A = ["the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"]

Input 2:
A = ["bit", "scale"]

Example Output

Output 1:
1

Output 2:
0
Output 1:
1

Output 2:
0

Example Explanation

Explanation 1:
We can check that all english alphabets are present in given sentence.

Explanation 2:
Not all english alphabets are present.
Explanation 1:
We can check that all english alphabets are present in given sentence.

Explanation 2:
Not all english alphabets are present.

Solution

swift
import Foundation

class Solution {
	func solve(_ A: inout [String]) -> Int {
        // let str = "abcdefghijklmnopqrstuvwxyz"
        
        let a:UnsafePointer<Int8> = "a"
        var m = [Character:Int]()
        for i in 0..<26{
            c = Character(a+i)
            m[c] = 0
        }
        
       
        // for c in str {
        //     m[c] = 0
        // }
        
        for str in A {
            for c in str {
                m[c] = 1
            }
        }
        
        for n in m.values{
            if n == 0 {
                return 0
            }
        }
        
        return 1
	}
}
import Foundation

class Solution {
	func solve(_ A: inout [String]) -> Int {
        // let str = "abcdefghijklmnopqrstuvwxyz"
        
        let a:UnsafePointer<Int8> = "a"
        var m = [Character:Int]()
        for i in 0..<26{
            c = Character(a+i)
            m[c] = 0
        }
        
       
        // for c in str {
        //     m[c] = 0
        // }
        
        for str in A {
            for c in str {
                m[c] = 1
            }
        }
        
        for n in m.values{
            if n == 0 {
                return 0
            }
        }
        
        return 1
	}
}

References