The problem involves tracking the frequency of IDs in a collection that changes over time. You have two integer arrays,
nums
andfreq
, of equal lengthn
. Each element innums
represents an ID, and the corresponding element infreq
indicates how many times that ID should be added to or removed from the collection at each step.
- Addition of IDs: If
freq[i]
is positive, it meansfreq[i]
IDs with the valuenums[i]
are added to the collection at stepi
.- Removal of IDs: If
freq[i]
is negative, it means-freq[i]
IDs with the valuenums[i]
are removed from the collection at stepi
.Return an array
ans
of lengthn
, whereans[i]
represents the count of the most frequent ID in the collection after theith
step. If the collection is empty at any step,ans[i]
should be 0 for that step.
c++
1 |
|