Infosys Interview Question

A simple leetcode question, easy level