I think we all agree that in the worst case, when all A unique or where all A same, you need to examine each element of the array to determine if there are duplicates or to determine the whole array contains one number. Like other posters, this will be O(N) . I'm not sure separation and victory will help you with the algorithmic complexity on this, although you can simplify the code a bit using recursion. To split and win really helps to cut Big O when you can throw away large parts of the input (e.g. binary search), but in the case when you potentially need to examine all the input data, it will not be much different.
I assume the result is that you are simply returning the size of the largest B you found, although you can easily change this to return B.
So, at the front of the algorithm, given that A is sorted, I'm not sure if the answer will be faster / simpler than just going through the array in order. It seems that the simplest answer is to have 2 pointers, one starting at index 0 and one starting at index 1. Compare them and then increase both of them; every time they are the same, you point the counter up to give you the current size B , and when they differ from you reset, which corresponds to zero. You also save the variable for the maximum size B that you have found so far, and update it every time you find a larger B
source share