Method 2: This method uses the technique of Linear Search to solve the following.
Time Complexity: O (m log n).#N#Where m is the number of distinct elements in the array of size n. Since m <= M (a constant) (elements are in a limited range), the time complexity of this solution is O (log n).