✅ Explained - Simple and Clear Python3 Code✅
Intuition\nThe problem asks us to determine whether a given three-digit number is fascinating or not. To be fascinating, the number must meet certain conditions
# Intuition\nThe problem asks us to determine whether a given three-digit number is fascinating or not. To be fascinating, the number must meet certain conditions after concatenating it with 2 * n and 3 * n. The conditions are that the resulting concatenated number should contain all digits from 1 to 9 exactly once and should not contain any zeros.\n\n\n# Approach\nTo solve the problem, we first concatenate the given number n with 2 * n and 3 * n. We convert these numbers to strings and concatenate them together. This gives us the concatenated string.\n\nNext, we check if the concatenated string contains any zeros. If it does, we immediately return false, as zeros are not allowed in the fascinating number.\n\nThen, we check if the length of the concatenated string is greater than 9. If it is, that means the concatenated string contains duplicate digits or additional digits beyond 1 to 9. In such a case, we return false.\n\nFinally, we iterate through the digits from 1 to 9 and check if each digit is present in the concatenated string. If any digit is missing, we return false. Otherwise, we return true, indicating that the number is fascinating.\n\n\n# Complexity\n- Time complexity:\nTime complexity: The time complexity of this approach is O(1) because the number of iterations and operations performed is constant, regardless of the input size. We are iterating through a fixed range (1 to 9) and performing a constant number of operations for each iteration.\n\n\n- Space complexity:\nSpace complexity: The space complexity is also O(1) because we are not using any additional data structures that grow with the input size. The space required is only for storing the concatenated string, which is of constant size since we are concatenating three fixed-size numbers.\n\n\n# Code\n```\nclass Solution:\n    def isFascinating(self, n: int) -> bool:\n        concatenated = str(n) + str(2 * n) + str(3 * n)\n\n        if \'0\' in concatenated:\n            return False\n        if len(concatenated)>9:\n            return False\n        for i in range(1,10):\n            if str(i) not in concatenated :\n                return False\n        return True\n```
['Python3']