Check if Any Permutation Forms a Factorion

You are given an integer n.

A number is called a factorion if the sum of the factorials of its digits is equal to the number itself.

Your task is to determine whether any valid permutation of the digits of n can form a factorion.

Return true if at least one such permutation exists, otherwise return false.

9

A valid permutation:

  • must use all digits of n exactly once
  • must not start with 0

Example 1:

Input: n = 154

Output: true

Explanation:

A valid permutation of the digits of 154 is 145.

Example 2:

Input: n = 210

Output: false

Explanation:

The valid permutations are 210, 201, 120, 102, and 021 / 012 are invalid because they start with 0.

None of the valid permutations is a factorion.

So, the answer is false.

Now Your Turn!

Pick the correct output for the given input

Input: n = 451

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= n <= 109
  • n contains at most 10 digits
  • All permutations must use every digit of n exactly once
  • Any permutation with a leading zero is invalid

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
bool isDigitorialPermutation(int n) {
// Your code goes here
}
};
Test Case

Input:

N