IBM Interview Question

Leetcode problem of medium difficulty