2
public int minNumberOfFrogs(String croakOfFrogs) {3
int[] index = new int[26];4
String corak = "croak";6
// Giving index to each characters7
for (int i = 0; i < corak.length(); ++i) index[corak.charAt(i) - 'a'] = i;10
int[] count = new int[5];12
for (char c : croakOfFrogs.toCharArray()) {13
int i = index[c - 'a'];14
// If it is not 'c' it will decrease the sum16
if (count[i - 1]-- <= 0) return -1;19
// If it is not 'k' it will increase the sum24
ans = Math.max(ans, sum);26
return sum == 0 ? ans : -1;