Check if The Number is Fascinating : - Time complexity: O(log(n)), Space complexity: O(1)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nCreate a HashMap to keep track of the digits encountered during the check
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nCreate a HashMap to keep track of the digits encountered during the checks.\n\nCompute 2*n and 3*n.\n\nIterate through the digits of n, 2*n, and 3*n, one by one.\n\nFor each digit encountered, check if it is already present in the HashMap or if it is equal to 0. If so, return false as it violates the fascinating condition.\n\nIf the digit is not already in the HashMap, add it to the HashMap.\n\nRepeat steps 3 to 5 for all digits in n, 2*n, and 3*n.\n\nIf all digits are unique and not equal to 0 in the HashMap, return true, indicating that the number is fascinating.\n\nIf any violation is found during the checks, return false.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(log(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public boolean isFascinating(int n) {\n        HashMap<Integer, Integer> m = new HashMap<>();\n\n        int a = 2*n;\n        int b = 3*n;\n        while(n >0){\n            int r = n%10;\n            if(m.containsKey(r) || r == 0){\n                return false;\n            }\n            else{\n                m.put(r,1);\n            }\n            n = n/10;\n\n        }\n        while(a >0){\n            int r = a%10;\n            if(m.containsKey(r) || r==0){\n                return false;\n            }\n            else{\n                m.put(r,1);\n            }                        \n            a = a/10;\n\n        }\n        while(b >0){\n            int r = b%10;\n            if(m.containsKey(r) || r==0){\n                return false;\n            }\n            else{\n                m.put(r,1);\n            }            \n            b = b/10;\n        }\n        return true;\n        \n    }\n}\n```
['Java']