Why would you make it so complicated? Why would you compute factorial. If there's a million elements in the array, your algorithm just cried.

Algorithm: sweep through the entire array. If the first element is equal to one, print zero. If the first element is equal to two, print one and zero. Now generalize that. There is a special case to consider it it's the last two elements that are missing, which falls into the same category of having an array of size N = 1.

It's O(n), which I believe means linear time? And it actually doens't use any additional memory.

You sweep through the array once and updating 2 variables. The first sums all the numbers in the array. The second multiply them. Now it's just a matter of solving 2 equation with 2 unknowns.

x + y = SUM[1..N] - t1 ; x * y = factorial[1..N] / t2.