Fact Digit Sum
Easy Accuracy: 17.38% Submissions: 144 Points: 2

A(X) for positive integer X is the sum of factorials of its digits. For example, A(154) = 1! + 5! + 4!= 145.
Given a number N, find the minimum number X such that A(X) = N. 


Example 1:

Input: N = 40321
Output: 18
Explanation: A(18)=1!+ 8! =40321 
Note that A(80) = A(81) is also 
40321, But 18 is the smallest 


Example 2:

Input: N = 5040
Output: 7
Explanation: A(7) = 7! = 5040.


Your Task:
You don't need to read or print anything. Your task is to complete the function FactDigit() which takes N as input parameter and returns a list of digits which represent the number X.


Expected Time Complexity: O(K) where K ≤ 106
Expected Space Complexity: O(K)


1 ≤ N ≤ 109

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Fact Digit Sum

Output Window