kt: add «1072. Flip Columns For Maximum Number of Equal Rows»

URL:	https://leetcode.com/problems/flip-columns-for-maximum-number-of-equal-rows/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-11-22 17:49:39 +01:00
parent 2e21177633
commit 8e196a299a
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,18 @@
class Solution {
fun maxEqualRowsAfterFlips(matrix: Array<IntArray>): Int {
val freqs = mutableMapOf<String, Int>()
matrix
.map { row ->
row.map { it == row[0] }.joinToString(separator = "")
}
.forEach { pattern ->
freqs.put(
pattern,
1 + freqs.getOrDefault(pattern, 0),
)
}
return freqs.values.max()
}
}