Created
November 23, 2014 04:44
-
-
Save binhngoc17/6deedf7ad6bd1d607250 to your computer and use it in GitHub Desktop.
Matrix Flip Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fileinput | |
inputs = fileinput.input() | |
input_vals = [] | |
for n in inputs: | |
input_vals.append(n.replace('\n', '')) | |
numRows, numCols=[int(i) for i in input_vals[0].split(' ')] | |
countMaxWishes = {} | |
for i in range(numRows): | |
row = input_vals[i+1] | |
flipToP = [] | |
flipToT = [] | |
for j in range(0, len(row)): | |
if row[j] == 'T': | |
flipToP.append(j) | |
else: | |
flipToT.append(j) | |
# As we iterate from the beginning so tuple(data[i]['P']) will uniquely identify | |
# a set of flips (We don't need to sort them) | |
countMaxWishes[tuple(flipToT)] = countMaxWishes.get(tuple(flipToT), 0) + 1 | |
countMaxWishes[tuple(flipToP)] = countMaxWishes.get(tuple(flipToP), 0) + 1 | |
print max(countMaxWishes.values()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment