Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
isaiahliu committed Dec 19, 2024
1 parent ea753ad commit 15ca3ea
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/main/kotlin/p31xx/Problem3138.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package p31xx

import util.expect

fun main() {
class Solution {
fun minAnagramLength(s: String): Int {
for (i in 1..s.length) {
if (s.length % i == 0) {
val set = hashSetOf<String>()

for (index in s.indices step i) {
set.add(s.substring(index, index + i).toCharArray().also { it.sort() }.concatToString())

if (set.size > 1) {
break
}
}

if (set.size == 1) {
return i
}
}
}

return s.length
}
}

expect {
Solution().minAnagramLength(
""
)
}
}

0 comments on commit 15ca3ea

Please sign in to comment.