LeetCode Entry
1903. Largest Odd Number in String
Largest odd number in a string
1903. Largest Odd Number in String easy
blog post
substack

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/431
Problem TLDR
Largest odd number in a string
Intuition
Just search for the last odd
Approach
Let’s write Kotlin one-liner
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(n)\)
Code
fun largestOddNumber(num: String): String =
num.dropLastWhile { it.toInt() % 2 == 0 }