Bar Problem O(nlogn)