I couldn’t figure out gas calculation in this challenge at first. For this reason, referring to below article.
https://stermi.xyz/blog/ethernaut-challenge-13-solution-gatekeeper-one