Hey is there a way to find the maximum occuring character in a string without using a hash map. ?
Maybe in dynamic Programming or something ???

Recommended Answers

All 4 Replies

Does it need to be efficient? If O(n2) is acceptable, you could just initialize an int array of the same size, then store the number of following characters that are equal. Then use the index of the largest int value to locate your maximum occurring character.

You mean letter of highest frequency? I think sorting by counting and finding the maximum is equivalent problem if you are not dealing with unicode.

@tony : ya sorting in O(n logn) and then an O(n) for finding duplicates is a good one.
@nmaillet : good one too, but the int array is like a hash map right???
thnks for the responese guys..

You can do this on O(n) using the fact that characters has a number associated with them. Here is live code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.