Hackerrank: correctness invariant - https://www.hackerrank.com/challenges/correctness-invariant