• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
September 19, 2022 |670 Views
Java Program to Return Maximum occurring Character in an Input String
  Share  2 Likes
Description
Discussion

In this video, we will write a JAVA program return the maximum occurring character in an input string.

For Example:
Input String = GeeksforGeeks
Output = e

Input String = TEST
Output = T

Here we use the “Hashing” method to return the maximum occurring character in an input string.

Algorithm:
Step 1: First we traverse through the string, we would hash each character into an array of ASCII characters. 
Step 2: Now we construct a character count array from the input string, and store the occurrence value.
Step 3: Print the index of the maximum value in the count array.

Example: 
Input = TEST
Output = T

Dry Run: 
count['T'] = 1
count['E’] = 1
count['S’'] = 1
count[‘T’]= 2

ASCII characters are 256, so we use our Hash array size as 256. But if we know that our input string will have characters with values from 0 to 127 only, we can limit the Hash array size to 128. Similarly, based on extra info known about input string, the Hash array size can be limited to 26.

Return maximum occurring character in input string:
https://www.geeksforgeeks.org/return-maximum-occurring-character-in-the-input-string/