QuantumBlack Interview Question

refer to hackerrank