LeetCode Entry
389. Find the Difference
Strings difference by a single char
389. Find the Difference easy
blog post
substack

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/350
Problem TLDR
Strings difference by a single char
Intuition
We can use frequency map. Or just calculate total sum by Char Int value.
Approach
Let’s use Kotlin’s API sumBy
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(1)\)
Code
fun findTheDifference(s: String, t: String) =
(t.sumBy { it.toInt() } - s.sumBy { it.toInt() }).toChar()