QuantumBlack interview question

refer to hackerrank