Back to questions

Rotating Factorial Microsoft Python Interview Question

Rotating Factorial

Microsoft Python Interview Question

Before, you work on this question, make sure you've solved the easier warmup problem Factorial Formula, where you need to write a function to compute nn factorial as follows:

n!=n(n1)(n2).....21 n! = n * (n-1) * (n-2) * ..... 2 * 1.

Now that you know the factorial formula, let's define a rotating factorial: instead of multiplying out all the numbers, we rotate between arithmetic operators like multiplication (), floor division (), addition (), and subtraction ().

For example, rotating_factorial(10) =109//8+765//4+321 = 10 * 9 // 8 + 7 - 6 * 5 // 4 + 3 - 2 * 1

When computing the above equation remember to apply PEMDAS (the order of operations) where multiplication and floor division come before addition/subtraction.

p.s. floor division is a type of division operation that returns the largest integer less than or equal to the result of dividing two numbers (aka we chop off the remainder and return a whole integer).

Floor Division Example: 13//4=313 // 4 = 3

Input

Python

Output