• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
July 18, 2024 |42.2K Views

Return maximum occurring character in an input string

  Share   Like
Description
Discussion

One obvious approach to solve this problem would be to sort the input string and then traverse through the sorted string to find the character which is occurring maximum number of times. Let us see if we can improve on this. So we will use a technique called ‘Hashing’. In this, when we traverse through the string, we would hash each character into an array of ASCII characters. 
 

Input string = “test”
1: Construct character count array from the input string.
 count['e'] = 1
 count['s'] = 1
 count['t'] = 2

2: Return the index of maximum value in count array (returns ‘t’).

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