Problem of the day
You are given an integer ’n’.
Your task is to return a sorted array (in increasing order) containing all the factorial numbers which are less than or equal to ‘n’.
The factorial number is a factorial of a positive integer, like 24 is a factorial number, as it is a factorial of 4.
In the output, you will see the array returned by you.
Example:
Input: ‘n’ = 7
Output: 1 2 6
Explanation: Factorial numbers less than or equal to ‘7’ are ‘1’, ‘2’, and ‘6’.
The first line contains one integer, ‘n’, denoting the integer.
Output format:
Return the array as described above.
Note:-
You don't need to print anything. Just implement the given function.
7
1 2 6
Input: ‘n’ = 7
Output: 1 2 6
Explanation: Factorial numbers less than or equal to ‘7’ are ‘1’, ‘2’, and ‘6’.
2
1 2
Input: ‘n’ = 2
Output: 1 2
Explanation: Factorial numbers less than or equal to ‘2’ are ‘1’ and ‘2’.
The expected time complexity is O(m), where ‘m’ is the number of factorial numbers which are less than or equal to ‘n’.
The expected space complexity is O(m), where ‘m’ is the number of factorial numbers which are less than or equal to ‘n’.
1 <= n <= 10^18
Time Limit: 1-sec