Didn't understood the logic of the solution provided

I couldn’t able to wrap my head around the soln given.Please help me here…

please send your code