How to implement it without passing count as reference

how to do it without passing count as reference because in java we can’t do it

There is no straight forward way for this
You need hacks
Some are given here
An easy one will be use some global variable

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.