GlobalLogic Interview Question

coding solution and logic building