Z-boson production in p-Pb collisions at $$\sqrt{s_{\mathrm{NN}}}$$ = 8.16 TeV and Pb-Pb collisions at $$\sqrt{s_{\mathrm{NN}}}$$ = 5.02 TeV