Jumping to Zero Problem of Graph Subsection of Preparing for FAANG Interview Solution is not passing all test cases

I have wrote. a solution of this problem and in one of the Test case it is showing memory Limit excedded. Can u help figure out why it is showing memory limit excedded.
I understand the another approach showing the solution but still I wanted to understand why my solution won’t work

https://ide.codingblocks.com/s/334514.

Please help here

Pass the ‘arr’ vector by reference.