is there a more efficient way?
Hi, I've been asked to build s method that finds the most frequent used letter (char).
I thought about a nested for loop that has two pointers and compares between the first and the second in the common way and when finding a match, increment a counter by one. Eventually returns the letter that counted the most.
My question is about the complexities because I'm not sure this is the most efficient way, and Ideas?
Thanks.
unfortunately I'm not allowed
to use that, I can use the String methods for my task.
I thought about creating an array but then if I go through it and then sort it, the complexity will be the same..
I thought also about going through the list ones and store each char in its designated place, for ex. if I come across 'a', an int a variable will be incremented and so on, so the outcome will look like:
a = 3
b = 1
c = 2
Then all I have to do is return the highest valued letter, in that case 'a'
but how do I do that without going through the list again (for complexity reasons)?
By the way it's recursive..