You are given a 0-indexed string num of length n consisting of digits.

Return true if for every index i in the range 0 &lt;= i &lt; n, the digit i occurs num[i] times in num, otherwise return false.

&nbsp;
Example 1:

Input: num = "1210"
Output: true
Explanation:
num[0] = '1'. The digit 0 occurs once in num.
num[1] = '2'. The digit 1 occurs twice in num.
num[2] = '1'. The digit 2 occurs once in num.
num[3] = '0'. The digit 3 occurs zero times in num.
The condition holds true for every index in "1210", so return true.


Example 2:

Input: num = "030"
Output: false
Explanation:
num[0] = '0'. The digit 0 should occur zero times, but actually occurs twice in num.
num[1] = '3'. The digit 1 should occur three times, but actually occurs zero times in num.
num[2] = '0'. The digit 2 occurs zero times in num.
The indices 0 and 1 both violate the condition, so return false.


&nbsp;
Constraints:


	n == num.length
	1 &lt;= n &lt;= 10
	num consists of digits.


from collections import Counter

class Solution:
    def digitCount(self, num: str) -> bool:
        d = Counter(num)
        for i in range(len(num)):
            if int(num[i])!=d.get(str(i), 0):
                return False
        return True
class Solution {
    public boolean digitCount(String num) {
        int[] freqArr = new int[10];  // n = 10 given in constraints;
        
        
        for(char ch : num.toCharArray()){
            freqArr[ch-'0']++;
        }
        
        for(int i=0;i<num.length();i++){
            int freq = num.charAt(i)-'0';  //freq of each indexValue;
            freqArr[i] = freqArr[i] - freq; 
        }
        for(int i=0;i<10;i++){
            if(freqArr[i]!=0){
                return false;
            }
        }
        return true;
    }
}
class Solution {
public:
    bool digitCount(string num) {
        unordered_map<int,int> mpp;
        int n= num.length();
        for(auto it:num){
            int x = it - '0';
            mpp[x]++; // Store the frequency of the char as a number
        }
        for(int i=0;i<n;i++){
            int x = num[i] - '0'; // get the char as number
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if(mpp[i] != x) // f the number is not equal to its frequency we return false
                return false;
        }
        return true;
    }
};
var digitCount = function(num) {    
    const res = [...num].filter((element, index) => {
        const reg = new RegExp(index, "g");
        const count = (num.match(reg) || []).length;
        
        return Number(element) === count
    })
    
    return res.length === num.length    
};
Check if Number Has Equal Digit Count and Digit Value