EASY JAVA BEATS 99%
Intuition\nconsidering {1210}\n\n    HASHMAP :\n\n    {\n        0:1\n        1:2\n        2:3\n    }\n\n    index : 0 1 2 3\n    number: 1 2 1 0\n\n    accordi
# Intuition\nconsidering {1210}\n\n    HASHMAP :\n\n    {\n        0:1\n        1:2\n        2:3\n    }\n\n    index : 0 1 2 3\n    number: 1 2 1 0\n\n    according to the question,\n\n    num[i] should be equal to frequency of index i\n\n    let x = num.charAt(i)\n    convert character to integer using -\n    int a = x - \'0\';\n\n    thus, if(a != frequency of a) i.e if(a != map.get(i)) return false;\n\n\n    but to avoid null pointer exception, we must check if the hashmap contains all indices or not, if it doesnt, then num[i] must be 0 as in this case,\n\nindex 3 is not in hashmap {\n        0:1\n        1:2\n        2:3\n    }\n\nso , if it doesnot contain in hashmap (! map.containsKey(i))\n\nthen check if num[i] must be 0, else return false;,\nif it is 0, then continue\n\n# Time Complexity - O(n)\n# Space Complexity - O(n)\n\n# Code\n```\nclass Solution {\n    public boolean digitCount(String num) {\n\n        //creating an integer - integer hashmap\n\n        HashMap<Integer, Integer> map = new HashMap<>();\n\n        for(int i = 0; i < num.length(); i++)\n        {\n            char x = num.charAt(i);\n\n            int a = x - \'0\'; // to create character to integer\n\n            if(map.containsKey(a))\n                map.put(a,map.get(a)+1);\n\n            else\n                map.put(a,1);\n\n        }\n\n        for(int i = 0; i<num.length(); i++)\n        {\n\n            // to avoid nullPointerException\n\n            if(!map.containsKey(i))\n            {\n                if(num.charAt(i)!=\'0\') //it must be 0, else false\n                    return false;\n                else //if it is 0, then continue\n                    continue;\n            }\n            char x = num.charAt(i); //let num[i] = x\n            int a = x - \'0\'; //convert x to int\n            if(a!=map.get(i)) //check if its equal to frequency\n                return false;\n\n        }\n\n        return true;\n    }\n}\n```
['Hash Table', 'Java']