Leetcode 2729: Check if The Number is Fascinating

grid47
grid47
Exploring patterns and algorithms
Feb 8, 2024 4 min read

You are given a three-digit integer n. We define a number as fascinating if, when you concatenate n, 2 * n, and 3 * n, the resulting number contains all digits from 1 to 9 exactly once and does not contain any zeros.
Problem
Approach
Steps
Complexity
Input: A three-digit integer n.
Example: n = 192
Constraints:
• 100 <= n <= 999
Output: Return true if the number is fascinating, otherwise return false.
Example: true
Constraints:
• The result will be a boolean value.
Goal: Determine if the concatenated number contains all digits from 1 to 9 exactly once without zeros.
Steps:
• Concatenate n, 2 * n, and 3 * n into a single string.
• Check if the string contains exactly the digits 1 to 9 with no repetitions or zeros.
Goal: The constraints ensure that n is a valid 3-digit number.
Steps:
• 100 <= n <= 999
Assumptions:
• n is always a valid three-digit number.
Input: Example 1
Explanation: For n = 192, concatenating 192, 384, and 576 gives 192384576, which contains all digits from 1 to 9 exactly once.

Input: Example 2
Explanation: For n = 100, concatenating 100, 200, and 300 gives 100200300, which contains zeros and doesn't satisfy the conditions.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus