Sie sind auf Seite 1von 1

string str="Interview is going on"

char[] str1=str.toCharArray()
int count=1;
int max_count=0;
char max_char='c'
char max_occ(char[] str1,int max_count,)
{
for(int i=1;i<str1.length;i++)
{
if(str1[i]==str1[i-1])
{
count++;
}
else{
if(count>max)
{
max_count=count;
max_char=str1[i-1]

}
count=1;
}
}
if(count>max_count)
{
max_count=count;
max_char=str1[str1.length-1]
}
return (max_char)
}

Char Maxoccurance(int arr[], int n, int k)


{
// Iterate though input array, for every element
// arr[i], increment arr[arr[i]%k] by k
for (int i = 0; i< n; i++)
arr[(arr[i]%k)] += k;

// Find index of the maximum repeating element


int max = arr[0], result = 0;
for (int i = 1; i < n; i++)
{
if (arr[i] > max)
{
max = arr[i];
result = i;
}
}

Das könnte Ihnen auch gefallen