  Measurements of the charge-dependent two-particle angular correlation
function in proton-lead (pPb) collisions at a nucleon-nucleon center-of-mass
energy of $\sqrt{s_\mathrm{NN}}$ = 8.16 TeV and lead-lead (PbPb) collisions
at$\sqrt{s_\mathrm{NN}}$ = 5.02 TeV are reported. The pPb and PbPb datasets
correspond to integrated luminosities of 186\nbinv and 0.607 nb$^{-1}$,
respectively, and were collected using the CMS detector at the CERN LHC. The
charge-dependent correlations are characterized by balance functions of same-
and opposite-sign particle pairs. The balance functions, which contain
information about the creation time of charged particle pairs and the
development of collectivity, are studied as functions of relative
pseudorapidity ($\Delta \eta$) and relative azimuthal angle ($\Delta \phi$),
for various multiplicity and transverse momentum ($p_\mathrm{T}$) intervals. A
multiplicity dependence of the balance function is observed in $\Delta \eta$
and $\Delta \phi$ for both systems. The width of the balance functions
decreases towards high-multiplicity collisions in the momentum region $\lt$2
GeV, for pPb and PbPb results. No multiplicity dependence is observed at higher
transverse momentum. The data are compared with HYDJET, HIJING and AMPT
generator predictions, none of which capture completely the multiplicity
dependence seen in the data.
