Related Articles
Check if a number is a Pangram or not
• Last Updated : 08 Apr, 2021

Given an integer N, the task is to check whether the given number is a pangram or not.
Note: A Pangram Number contains every digit [0- 9] at least once.

Examples:

Input : N = 10239876540022
Output : Yes
Explanation: N contains all the digits from 0 to 9. Therefore, it is a pangram.

Input : N = 234567890
Output : No
Explanation: N doesn’t contain the digit 1. Therefore, it is not a pangram.

Set-based Approach: The idea is to use Sets to store the count of distinct digits present in N. Follow the steps below to solve the problem:

Below is the implementation of the above approach:

## Java

 `// Java implementation of above approach``import` `java.math.BigInteger;``import` `java.util.HashSet;` `class` `GFG{``    ` `// Function to check if N``// is a Pangram or not``static` `String numberPangram(BigInteger N)``{``    ` `    ``// Stores equivalent string``    ``// representation of N``    ``String num = N.toString();` `    ``// Convert the string to Character array``    ``char``[] arrNum = num.toCharArray();` `    ``// Add all characters pf arrNum to set``    ``HashSet setNum = ``new` `HashSet();` `    ``for``(``char` `ch : arrNum)``    ``{``        ``setNum.add(ch);``    ``}``    ` `    ``// If the length of set is 10``    ``// The number is a Pangram``    ``if` `(setNum.size() == ``10``)``        ``return` `"True"``;``    ``else``        ``return` `"False"``;``}` `// Driver code``public` `static` `void` `main(String[] args)``{``    ``BigInteger N = ``new` `BigInteger(``"10239876540022"``);``    ``System.out.print(numberPangram(N));``}``}` `// This code is contributed by abhinavjain194`

## Python3

 `# Python3 implementation of above approach` `# Function to check if N``# is a Pangram or not``def` `numberPangram(N):``  ` `    ``# Stores equivalent string``    ``# representation of N``    ``num ``=` `str``(N)``    ` `    ``# Convert the string to set``    ``setnum ``=` `set``(num)``    ` `    ``# If the length of set is 10``    ``if``(``len``(setnum) ``=``=` `10``):``      ` `          ``# The number is a Pangram``        ``return` `True``    ``else``:``        ``return` `False`  `# Driver Code` `N ``=` `10239876540022``print``(numberPangram(N))`
Output:
`True`

Time Complexity: O(log10N * log(log10N))
Auxiliary Space: O(1)

Hashing-based Approach: Follow the steps to solve the problem:

Below is the implementation of the above approach:

## Python3

 `# Python implementation of above approach` `from` `collections ``import` `Counter` `# Function to check if``# N is a Pangram or not``def` `numberPangram(N):``  ` `    ``# Stores equivalent string``    ``# representation of N``    ``num ``=` `str``(N)``    ` `    ``# Count frequencies of``    ``# digits present in N``    ``frequency ``=` `Counter(num)``    ` `    ``# If the length of the``    ``# dictionary frequency is 10``    ``if``(``len``(frequency) ``=``=` `10``):``      ` `          ``# The number is a Pangram``        ``return` `True``    ``else``:``        ``return` `False`  `# Driver Code` `N ``=``10239876540022``print``(numberPangram(N))`
Output:
`True`

Time Complexity: O(log10N * log(log10N))
Auxiliary Space: O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up