All questions
MediumStrings · Sorting
Anagram Number
Written by a community member · · 1 attempt · 100% pass
0
Write a function that determines whether a given positive integer is an anagram number.
An anagram number is a number that can be multiplied by at least one single-digit factor other than 1 to produce a result whose digits are an anagram of the original number's digits.
Implement:
is_anagram_number(n: int) -> bool
Rules:
- Consider only single-digit factors from 2 through 9.
- A multiplication result qualifies if it has exactly the same digits as the original number, just in a different order.
- Repeated digits count normally; leading zeros are not allowed in the comparison.
- Return
Trueif at least one factor works, otherwiseFalse.
Examples:
is_anagram_number(125874)returnsTruebecause125874 * 2 = 251748, which uses the same digits.is_anagram_number(123)returnsFalsebecause no factor from 2 to 9 produces an anagram of123.
Constraints:
1 <= n <= 10**18- The input is guaranteed to be an integer.