Quantcast interview question

4h hour coding exercise on Hackerrank