If $f(x)=e^{-x}x^n$, find the values of $n$ such that $f(x)$ has $0,1, 2$ or $3$ inflection points. 
If $f(x)=e^{-x}x^n$, $n\in \mathbb{Z}$, find the values of $n$ such
that $f(x)$ has $0,1, 2$ or $3$ inflection points. (That is, give the set of $n$ for each possible number of inflection points (0,1,2,3).)

This is a question that I found in a past exam paper for a math subject in Australia.
The previous parts of the question ask to find $f''(x)$ and to find $x: f''(x)=0, x\neq 0$
The answers are $f''(x)= e^{-x} x^{n - 2} (n^2 - n (2 x + 1) + x^2)$, and for the next part, $x=n\pm \sqrt{n}$ ($\neq0$).
So for the question I've asked, I actually did solve it, but in a fairly long winded way. As an inflection point is defined if the following conditions are met: $f''(x)=0,  \frac{f''(x+a)}{f''(x-a)}<0$, (the last condition saying that the value of $f''(x)$ in the neighbourhood of the x-intercept of $f''(x)$ are opposite signs immediately to the left and right of it.), I did the following:
For each of the factors in $f''(x)$, consider when they would satisfy the alternating sign condition, then I essentially intersected each set of n-values to arrive at the answer.
0 POIs:  $n\in \mathbb{Z}^-\cup \{0\}$
1 POI: $n=1$
2 POIs: $n=2k, k\in \mathbb{Z}^+$
3 POIs: $n=2k+1, k\in \mathbb{Z}^+$
The problem though is that this took too long, and the question was only worth 2 marks which really means that it shouldn't take more than a few minutes to figure out.
My question: is there are nicer less complex way of solving this? My method involved intersecting a bunch of sets and considering certain 'edge' cases, which doesn't seem very efficient at all.
 A: Let's start from where you set the second derivative equal to zero: $e^xx^{n-2}(x^2 - 2nx + (n^2 - n)) = 0$. Notice that we can divide both sides by the $e^x$ because it's never zero, so $x^{n-2}(x^2 - 2nx + (n^2 - n)) = 0$, and now our equation is polynomial.
Now we can use one of the properties of the roots of a polynomial, which is that if we have a root with an even multiplicity, then the polynomial will have the same sign on either side, but if we have a root with an odd multiplicity, then the polynomial will have opposite signs on either side. So, we want to look for roots with odd multiplicities.
For the first term, $x^{n-2}$, if $n > 2$ we will have a root at $x = 0$. If $n$ is even, this will have even multiplicity, otherwise it will have odd multiplicity.
Let's look at the first term: $x^{n-2} = 0$. When $n \leq 2$, this trivially has no solutions. Otherwise, we get a root at $x = 0$ with even multiplicity if $n$ is even, otherwise odd multiplicity if $n$ is odd.
Now let's look at the second term: $x^2 - 2nx + (n^2 - n) = 0$. Let's look at the discriminant, which is the expression under the square root in the quadratic formula: $(-2n)^2 - 4(1)(n^2 - n) = n$. So when $n < 0$, we get no real roots, when $n = 0$ we get one double root, and when $n > 0$ we get two distinct real roots with multiplicity $1$.
There is a potential concern here with whether the roots from the two terms will match up, so let's consider if $x = 0$ is ever a root of the second term. If $x = 0$ is a root of the second term, then we must have $n^2 - n = 0$, so $n$ is $0$ or $1$. But when $n$ is $0$ or $1$, our expression is undefined at $x = 0$ due to division by zero, so we have to disregard this root.
So, for $n \leq 0$ we have no roots, and therefore no points of inflection.
When $n = 1$, the first term has no roots and the second term gives two roots with multiplicity $1$, but we have to ignore the root at $x = 0$ so we get one point of inflectin.
For $n \geq 2$, the second term gives us $2$ points of inflection for every value of $n$, and the first gives one additional point of inflection if $n$ is odd. This matches your answer.
