ArrayList used and not taught till this question

Till the time I came to this ques, we aren’t taught ArrayList and expected to use this. why?
I did the ques using another way and it showed TLE for case 0.
Is there any way other than ArrayList?