From 8e196a299a22a0694079b94d09fb97d831a8c608 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 22 Nov 2024 17:49:39 +0100 Subject: [PATCH] =?UTF-8?q?kt:=20add=20=C2=AB1072.=20Flip=20Columns=20For?= =?UTF-8?q?=20Maximum=20Number=20of=20Equal=20Rows=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit URL: https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows/ Signed-off-by: Matej Focko --- ...columns-for-maximum-number-of-equal-rows.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 kt/flip-columns-for-maximum-number-of-equal-rows.kt 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() + } +}