This now passes the 2 main tests on Hackerrank.
However, it fails the other 3 which are not provided.