diff --git a/kt/flip-columns-for-maximum-number-of-equal-rows.kt b/kt/flip-columns-for-maximum-number-of-equal-rows.kt new file mode 100644 index 0000000..3cf5df5 --- /dev/null +++ b/kt/flip-columns-for-maximum-number-of-equal-rows.kt @@ -0,0 +1,18 @@ +class Solution { + fun maxEqualRowsAfterFlips(matrix: Array): Int { + val freqs = mutableMapOf() + + matrix + .map { row -> + row.map { it == row[0] }.joinToString(separator = "") + } + .forEach { pattern -> + freqs.put( + pattern, + 1 + freqs.getOrDefault(pattern, 0), + ) + } + + return freqs.values.max() + } +}