Search in a nearly sorted array in O(logn) time

Given a nearly sorted array such that each of the N elements may be misplaced by no more than one position from the correct sorted order, efficiently search a given element in it. Report if the element is not present in the input array.   An element at index i in correct sorted order can …

Print all Triplets that forms Arithmetic Progression

Given a sorted array of distinct positive integers, print all triplets that forms Arithmetic Progression with integral common difference.   An Arithmetic Progression is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15, . . . is an arithmetic progression …