transpose and flatten hackerrank solution in python