Hackerrank Flipping Matrix Solution