naive solution; not suffix array one