# 04.12.2023 [2264. Largest 3-Same-Digit Number in String]
Largest 3-same-digit number in a string
04.12.2023
2264. Largest 3-Same-Digit Number in String easy
blog post
youtube
Join me on Telegram
https://t.me/leetcode_daily_unstoppable/427
Problem TLDR
Largest 3-same-digit number in a string
Intuition
There are 10 such numbers in total: 000, 111, ..., 999
.
Approach
Let’s use Kotlin’s API
Complexity
Time complexity:
O(n)Space complexity:
O(n), can be O(1) withasSequence()
Code
fun largestGoodInteger(num: String): String =
num.windowed(3)
.filter { it[0] == it[1] && it[0] == it[2] }
.maxByOrNull { it[0] } ?: ""