Hexaware Technologies Interview Question

Similar to the Leetcode problem.