C++ | Brute Force | Beginner Friendly | Sorting | O(n log n)
Intuition\nThe code checks if a number n is fascinating or not. To determine this, it concatenates n, 2n, and 3n into a single string and sorts it. By iterating
**Intuition**\nThe code checks if a number n is fascinating or not. To determine this, it concatenates n, 2*n, and 3*n into a single string and sorts it. By iterating through the sorted string, if any digit is \'0\' or there are repeated digits, the number is not fascinating. Otherwise, it is considered fascinating.\n\n**Time Complexity**\nThe time complexity of sorting an array of size n using a comparison-based sorting algorithm, such as the one used in the std::sort function, is generally O(n log n). The for loop iterates through the sorted string, which also takes O(n) time.\n\n**Code**\n```\nclass Solution {\npublic:\n    bool isFascinating(int n) {\n        // Create variables for 2*n and 3*n.\n        int n2 = 2 * n;\n        int n3 = 3 * n;\n        \n        // Convert the numbers to strings.\n        string s = to_string(n);\n        string s2 = to_string(n2);\n        string s3 = to_string(n3);\n\n        // Concatenate the strings.\n        string ans = s + s2 + s3;\n        \n        // Sort the concatenated string.\n        sort(ans.begin(), ans.end());\n        \n        // Check for \'0\' or repeated digits.\n        for (int i = 0; i < ans.size() - 1; i++) {\n            if (ans[i] == \'0\' || ans[i] == ans[i + 1]) {\n                return false;\n            }\n        }\n        \n        return true; \n    }\n};\n```\n\nPlease consider upvoting and leaving any comments or feedback if you found the solution helpful. Thank you! \uD83D\uDE0A
['C', 'Sorting', 'C++']