Coding Question - Max Consecutive Characters

Posted by Matthew Osborn on April 5, 2008

Recently I was asked to code a simple method.  This method should take in two parameters a string and a character.  The goal of the method was to count the max number of consecutive times the character parameter appeared in the string.  So an example would be that the string “abaabbaaa” is passed into the method along with the character ‘a’ The method should then return 3 because the character ‘a’ appears 3 times in a row.  This seems like a very simple method but it is actually very trick to make it efficient.  So let see what you guys can come up with, post your solution in the comments section.  I will be posting the solution in a few days.