Find a new quadratic form through change of variables Consider a quadratic form $$f(x) = \sum_{i=1}^{n}a_i x_i ^2$$ $f$ represents $0$ non-trivially. Then I need to show that by a linear change of variables, I can get the following quadratic form $$f(y) = \sum_{i=1}^{n-2}b_i y_i ^2 - 2 b_ny_{n-1}y_n$$
Now as suggested in Find a change in variable that will reduce the quadratic form to a sum of squares by Gerry Myerson, I put $x = Py$ , for some $n \times n$ matrix $P$. Then $$f(x)=f(Py)=(Py)^tAPy=y^t(P^tAP)y$$ My question is how do I find the matrix $P$ s.t. I get $f(y)$ as mentioned above. 

I should emphasize that the linear change of variables for a quadratic form is typically taken to be a matrix $P$ of determinant $1,$ with transformed matrix $P^T A P.$ It is not generally required that $P$ be orthogonal. 
The question as stated is false for $n-1$ positive diagonal elements and a single zero. It is true if there are at least two zeros, just permute so those are at the end, your $b_n$ becomes zero. Permuting by a matrix $P$ of determinant $+1,$  that is $P^T A P$ for a pair of diagonal entries, is
$$
\left(
\begin{array}{rr}
0 & -1 \\
1 & 0
\end{array}
\right)
\left(
\begin{array}{rr}
u & 0 \\
0 & v
\end{array}
\right)
\left(
\begin{array}{rr}
0 & 1 \\
-1 & 0
\end{array}
\right) =
\left(
\begin{array}{rr}
v & 0 \\
0 & u
\end{array}
\right)
$$ 
If there are at least one positive diagonal entry and one negative, first consider their product to be $-1.$ Permute, two entries at a time, so that these are the last two diagonal entries.
Then
$$
\left(
\begin{array}{rr}
\frac{1}{2} & -\frac{w}{2} \\
\frac{1}{w} & 1
\end{array}
\right)
\left(
\begin{array}{rr}
w & 0 \\
0 & - \frac{1}{w}
\end{array}
\right)
\left(
\begin{array}{rr}
\frac{1}{2} & \frac{1}{w} \\
- \frac{w}{2} & 1
\end{array}
\right) =
\left(
\begin{array}{rr}
0 & 1 \\
1 & 0
\end{array}
\right)
$$
This is a small part of Lemma 2.1 on page 15 of Rational Quadratic Forms by Cassels, that a regular isotropic quadratic space contains a hyperbolic plane. I recommend Cassels. 
If the product of the two diagonal elements is $- c^2$ for real $c,$ we can find an appropriate $w$ to give
$$
\left(
\begin{array}{rr}
\frac{1}{2} & -\frac{w}{2} \\
\frac{1}{w} & 1
\end{array}
\right)
\left(
\begin{array}{rr}
cw & 0 \\
0 & - \frac{c}{w}
\end{array}
\right)
\left(
\begin{array}{rr}
\frac{1}{2} & \frac{1}{w} \\
- \frac{w}{2} & 1
\end{array}
\right) =
\left(
\begin{array}{rr}
0 & c \\
c & 0
\end{array}
\right)
$$
