
We know the time complexity of Binary Search algorithm: Best Case – O(1) i.e. Therefore we will use the existing algorithm Binary Search that will help us finding the start and end index of an element in array optimally. We can simply iterate through array elements and find the start and end index of an element in array but that would not give us the optimal solution. We may design the algorithm for finding start and end index of an element in a sorted array in various ways but we need to consider also for the optimized solution. The array may contain duplicate elements and we will see how to find a start and end index for an element in this array elements.

Finding start and end index of an element in a sorted array using Kotlin programming language will be shown here.
