Determine all functions $f:\mathbb{R} \to \mathbb{R}$ such that $$f(x f(x+y))+f(f(y) f(x+y))=(x+y)^{2}, \forall x,y \in \mathbb{R} \tag1)$$
My approach: Let $x=0$, we get $$f(0)+f\left((f(y))^2\right)=y^2$$ $\Rightarrow$ $$f\left((f(y))^2\right)=y^2-f(0)\tag2 $$ Let us assume $f(0)=k \ne 0$
Put $y=0$ above, we get $$f(k^2)=-k$$ Also put $y=-x$ in $(1)$, we get $$f(kf(x))+f(kf(-x))=0, \forall x \in \mathbb{R}$$ Put $x=0$ above we get $$f(k^2)=0$$ $\Rightarrow$ $f(k^2)$ has two different images $0,-k$ which contradicts that $f$ is a function. Hence $k=0 \Rightarrow f(0)=0$. So from $(2)$ we get: $$f\left((f(y))^2\right)=y^2 \cdots (3)$$ Now put $y=0, x=f(x)$ in $(1)$, and use the fact $f(0)=0$,we get $$f\left((f(x))^2\right)=(f(x))^2$$ Since $x$ is dummy variable, we get $$f\left((f(y))^2\right)=(f(y))^2 \cdots (4)$$ From $(3),(4)$, we get $$f(x)=\pm x$$
I just want to ask, is my approach fine? If not where is the flaw? Also other approaches are welcomed.
My attempt was to show that $f(0)=0$.. And I did it.
\begin{align} P(0, y): \; & f(0)+f(f(y)^2)=y^2. \\ P(0, 0): \; & f(0)+f(f(0)^2)=0. \\ & \text{let } f(0)=k. \\ \ \\ \Rightarrow \; & k+f(f(y)^2)=y^2, k+f(k^2)=0. \\ \ \\ & \text{let } f(a)^2=f(b)^2. \\ P(0, a): \; & k+f(f(a)^2)=a^2. \\ P(0, b): \; & k+f(f(b)^2)=b^2. \\ \therefore \; & f(a)^2=f(b)^2 \Leftrightarrow a^2=b^2. \\ \ \\ P(k, -k): \; & f(kf(0))+f(f(-k)f(0))=0. \\ \Rightarrow \; & f(k^2)+f(kf(-k))=0, f(kf(-k))=k. \\ \ \\ P(-k, 0): \; & f(-kf(-k))+f(kf(-k))=k^2. \\ \Rightarrow \; & f(-kf(-k))=k^2-k. \\ P(k, -2k): \; & f(kf(-k))+f(f(-2k)f(-k))=k^2. \\ \Rightarrow \; & f(f(-2k)f(-k))=k^2-k. \\ \ \\ \Rightarrow \; & f(-kf(-k))=f(f(-2k)f(-k)). \\ \Rightarrow \; & f(-kf(-k))^2=f(f(-2k)f(-k))^2. \\ \ \\ \therefore \; & k^2f(-k)^2=f(-2k)^2f(-k)^2, k^2=f(-2k)^2. \\ \Rightarrow \; & f(0)^2=f(-2k)^2, 4k^2=0, k=0. \\ \therefore \; & f(0)=0. \\ \ \\ \ \\ \end{align}