Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
On every duplicate you create a new instance starting from 0, instead of this you should save the state somewhere, use a Map structure and use the encountered number as index and it's occurrence as value, zerofill the map slot based on whether the number appears now or increment if it reappears.
6th Oct 2021, 1:40 PM
Valen.H. ~
Valen.H. ~ - avatar