Infosys interview question

A simple leetcode question, easy level