DMITRII’s Substack

Share this post

Leetcode daily # 18.05.2023

dmitriisamoilenko.substack.com

Leetcode daily # 18.05.2023

[1768. Merge Strings Alternately]

DMITRII SAMOILENKO
Apr 18, 2023
Share
Share this post

Leetcode daily # 18.05.2023

dmitriisamoilenko.substack.com

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("")

blog post

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 operator

  • for the tail, consider drop

Complexity

  • Time complexity:
    O(n)

  • Space complexity:
    O(n)

Thanks for reading DMITRII’s Substack! Subscribe for free to receive new posts and support my work.

Share
Share this post

Leetcode daily # 18.05.2023

dmitriisamoilenko.substack.com
Previous
Next
Comments
Top
New

No posts

Ready for more?

© 2023 DMITRII SAMOILENKO
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing