What I am trying to achieve is, when there is a given word, I need to find out the second most frequent character within that string.
In additions to that, there is some more options I want to achieve. For example,
If a string, "ababababd" is given, there are four 'a's, four 'b's, and one 'd', so in this case, I need to printout 'd'.
If a string is "ababababdc" is given, there are four 'a's, four 'b's, one 'd' and 'c', I need to printout 'dc'
public class MemorizeWorld { public static void main(String[] args) { Solution solution = new Solution(); String a = "ababababd"; solution.solution(a); } } class Solution { public void solution(String a) { int[] array = new int[26]; char[] char_array = a.toCharArray(); for(int i = 0; i < char_array.length; i++) { int index = char_array[i] - 'a'; array[index]++; } int max = 0; for(int i = 0; i < array.length; i++) { if(array[i] > max) { max = array[i]; } } } }
This is what I have done so far and I am stuck on getting a solution. I know how to get the second most frequent character by following the post from geeksforgeeks, but I don't know how I should apply those two options above to that. Is there anyone who can help me with this problem?