How to find index in sorted array where occurs maximum value for the first time?
Let's take for example this array:
1 2 3 4 5 6 7 8 9 ... 200 201 201 201 201 201 201 201 201 201 201 201 201 ...201
where 201
is the maximum value.
Let's say that 201
occurs 200 times in this array. So the answer is that the index equals 200.
The native solution would be to iterate it as long as we get sth that !=201
. But I guess that it is possible to find more effective solution. What algorithm do you suggest?