Given X+Y+Z = 0, find $\frac{(X^3+Y^3+Z^3)}{XYZ}$ The result can be found using the equation :
$(X^3+Y^3+Z^3) - 3XYZ = (X+Y+Z)(X^2 - XY +Y^2 - YZ +Z^2 - XZ)$
Since X+Y+Z = 0, the right side of the equation is equal to 0. Therefore $X^3+Y^3+Z^3 = 3XYZ$ and the answer to the problem is 3.
However what if we calculate $X^3+Y^3+Z^3$ as $(X+Y+Z)^3 - 3X^2Y - 3Y^2X - 3X^2Z - 3z^2X - 3Y^2Z - 3Z^2Y$. $(X+Y+Z)^3 = 0$, so $X^3+Y^3+Z^3$ can be replaced with $- 3X^2Y - 3Y^2X - 3X^2Z - 3Z^2X - 3Y^2Z - 3Z^2Y$.
$\frac{- 3X^2Y - 3Y^2X - 3X^2Z - 3Z^2X - 3Y^2Z - 3Z^2Y}{XYZ}$ = $\frac{-3X - 3Y}{Z} - \frac{-3X-3Z}{Y} - \frac{-3Y-3Z}{X}$
If X+Y+Z = 0, consequenty 3X+3Y+3Z = 0. Our expression can be rewritten as $\frac{-3Z}{Z} + \frac{-3Y}{Y} +\frac{-3X}{X}$, so the answer is -9.
Could you please tell me which way of solving this problem is right and why

The first attempt is correct, assuming that $X, Y, Z \neq 0$. You can verify this with a simple example, say $X = Y = 1, Z = -2$. The mistake in the second attempt is due to the fact that you have missed a term in your expression of $X^3 + Y^3 + Z^3$. Specifically,
$$(X + Y + Z)^3 = X^3 + Y^3 + Z^3 + 3(X^2 Y + Y^2 X + X^2 Z + Z^2 X + Y^2 Z + Z^2 Y) + \color{blue}{6XYZ}$$
To avoid errors like the one you made, always check that the number of terms in your expansion is correct! We expect $3^3 = 27$ terms in the expansion of $(X + Y + Z)^3$, and your expansion only gave $21$. You can then plug this into your second method and you will see that you get the correct answer of $3$.
