But the OP asked about optimum AND maximum altitude. By definition if you are talking about maximum altitude you are talking about operating at maximum cruise power and the TET limit that goes with that.
Although you can say that thrust varies with density that is not a complete statement. A more accurate statement would be that at a given rpm thrust varies with density.
As temperature above ISA increases the rpm has to be reduced to keep inside the TET limit,
So a full answer to the OP is not as simple as "density"