to make it O(n logn) 1.Chose one index O(n) 2.For this index do a bsearch on remaining array to find the postion bsearch can be done as the array is an increasing function(it donotes no of occurrence of each word,so>=previous index value)
bsearch will be done like this 1.make a new temp array that is sum of the array to be found([1,1,1,1])and the chosen index array 2.now take the middle element array if all values of array are eual to temp array u have ans; if any one value is lesser go to right half else goto left half finally while returnin(after while loop) do chck greater than condition again --