The problem can be solved using discrete Fourier transform (DFT).
Rewriting the problem as a matrix equation Cx = b
, we noticed that the
coefficient matrix C
is a circulant square matrix. The equation can then be
rewriten as the circular convolution of c
and x
.
By circular convolution theorem, the point-wise product of the DFT of c
and
that of x
is the DFT of b
. We can compute x
from the point-wise quotient.
(Wikipedia)
- We compute
x
. - We iterate
x
to find the youngest player.
The running time of this algorithm is bounded by DFT. When using DFT, we can
achieve O(n^2)
. If we use fast Fourier transform, the upper bound can be
reduced to O(n log n)
.