18.05.2023
1768. Merge Strings Alternately easy
fun mergeAlternately(word1: String, word2: String): String =
(word1.asSequence().zip(word2.asSequence()) { a, b -> "$a$b" } +
word1.drop(word2.length) + word2.drop(word1.length))
.joinToString("")
Join me on Telegram
https://t.me/leetcode_daily_unstoppable/184
Intuition
Do what is asked.
Handle the tail.
Approach
we can use sequence
zip
operatorfor the tail, consider
drop
Complexity
Time complexity:
O(n)Space complexity:
O(n)