I am having trouble understanding the concept

During the dry run i am getting wrong answer it would be beneficial if you could share the relevant code with me.
: