LeetCode Entry
1704. Determine if String Halves Are Alike
Let's use some Kotlin's API
1704. Determine if String Halves Are Alike easy
blog post
substack
youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/469
Problem TLDR
https://t.me/leetcode_daily_unstoppable/469
Approach
Let’s use some Kotlin’s API:
- toSet
- take
- drop
- count
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(n)\), can be O(1) with
asSequence
Code
val vw = "aeiouAEIOU".toSet()
fun halvesAreAlike(s: String) =
s.take(s.length / 2).count { it in vw } ==
s.drop(s.length / 2).count { it in vw }