My work is working fine on ecllipse. but during submission showing wrong answer

my code is working fine and printing the index of the reverse array . please tell me whats wrong with my code

Hi Aditya,
In your code first you are sorting the array and then applying search.Your code has a time complexity of O(n^2){due to bubble sort}.
But if we again sort the array,it will lead to much time.
As his freind shuffled the array elements,we need not to sort the array again.Try to find an approach to find the element without sorting the array.
Thankyou.

but i just simply reverse the array after sorting the array … there is no need to sort again. the compiler during shows me wrong answer … in case of time complexity it must show me time limit error . may you please see it again

@Adi_choudhary
The mistakes are:

  1. You are printing the array element which is to be found,and we have to print index.
    2.You don’t need to change the array means Consider The given rotated array as [4, 5, 1, 2, 3]. The element to be searched is 2.
    Now if you sort the Array becomes [1,2,3,4,5] and 2 is to be searched resulting in index 1 as answer.
    But required answer is 3 which need to be searched in the original given Array[4,5,1,2,3].
    thankyou.
1 Like