Google Guava’s Multiset Interface in Java

A Multiset is a collection that is similar to Set, but it may have duplicate elements. It supports duplicate elements by maintaining a count of number of times an element appears in the collection. In this post, we will see how to use Multiset provided by Google’s Guava Library.

Search in a nearly sorted array in log(n) 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.