-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxNoOfBalloon.java
More file actions
23 lines (21 loc) · 827 Bytes
/
maxNoOfBalloon.java
File metadata and controls
23 lines (21 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.HashMap;
public class maxNoOfBalloon {
public static int maxNumberOfBalloons(String text) {
if (text.length()>=7) {
HashMap<Character, Integer> m=new HashMap<>();
for (char ch : text.toCharArray()) {
if (ch=='b'||ch=='a'||ch=='l'||ch=='o'||ch=='n') {
m.put(ch, m.getOrDefault(ch, 0)+1);
}
}
int mi1=Math.min(m.getOrDefault('b', 0),Math.min(m.getOrDefault('a', 0),m.getOrDefault('n', 0)));
int mi2=Math.min(m.getOrDefault('l', 0)/2,m.getOrDefault('o', 0)/2);
return Math.min(mi1, mi2);
}
return 0;
}
public static void main(String[] args) {
int i=maxNumberOfBalloons("ballo");
System.out.println(i);
}
}