and what is binary search space ??
What is the problem in this code?
Hey binary search is always applies on sorted array. Here given input array is not sorted, so sort it first. Also in your answer() function you have to take take difference between current array element and previously used index not adjacent index (a[i]-a[i-1] is wrong).
Time complexity of your code is O(nlogn) and space complexity is O(n).
by my mistke i am not able to give the rating?? can i give it again??