LeetCode Entry
1189. Maximum Number of Balloons
Count "balloon"s in stirng
1189. Maximum Number of Balloons easy substack youtube
https://dmitrysamoylenko.com/leetcode/

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