Count Inversions Hackerrank Sql Intermediate