LeetCode Entry

1189. Maximum Number of Balloons

22.06.2026 easy 2026 kotlin rust

Count "balloon"s in stirng

1189. Maximum Number of Balloons easy substack youtube

https://dmitrysamoylenko.com/leetcode/

22.06.2026.webp

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1398

Problem TLDR

Count “balloon”s in stirng

Intuition

Calculate the frequency; Divide the frequency of ‘l’ and ‘o’ by 2.

Approach

  • we can iterate 5 times

Complexity

  • Time complexity: \(O(n)\)

  • Space complexity: \(O(1)\)

Code

    fun maxNumberOfBalloons(t: String) =
    (0..4).minOf {t.count{c->c=="balon"[it]}/(it/2%2+1)}
    pub fn max_number_of_balloons(t: String) -> i32 {
        "balon".chars().map(|c|
        t.matches(c).count()/((c=='l'||c=='o')as usize+1)).min().unwrap() as _
    }

Comments