I am trying to solve $$\max_{g_0,...,g_{M-1}} \left|\sum_{m=0}^{M-1} g_m\right|^2\ \text{s.t.}\ \sum_{m=0}^{M-1} |g_m|^2=M,\ \sum_{m=0}^{M-1} g_m |g_m|^2=0.$$ where $g_m$ can be complex. The problem does not seem easy to solve for me.

Intuitively, I would conjecture that an optimal $g_m$ should be purely real up to a constant phasor ($g_me^{\jmath \phi}$ achieves the same cost function as $g_m$ and also meets the constraints if $g_m$ does). If this phasor is set to one, the problem is converted to an all real problem $$\max_{g_0,...,g_{M-1}} \left(\sum_{m=0}^{M-1} g_m\right)^2\ \text{s.t.}\ \sum_{m=0}^{M-1} g_m^2=M,\ \sum_{m=0}^{M-1} g_m^3=0.$$ I can find the globally optimal solution of this problem using the Lagrangian, setting its derivative to zero, and finding the global optimum among the different critical points. The optimal solution is then "simply" to set all $g_m$ to the same value except for one with an opposite sign to meet the second constraint. For instance, using first element as the opposite one \begin{align*} g_m&=\frac{\sqrt{M}}{\sqrt{M-1+(M-1)^{2/3}}}\begin{cases} - \left(M-1\right)^{1/3}\ &\text{if}\ m=0\\ 1\ &\text{otherwise} \end{cases}. \end{align*}

Of course all of that relies on the conjecture, which I find hard to prove... Any idea? Thank you for your help!