Doubt on leetcode

pLease help me with the approach of this problem