In the Dominant Piranha question, why was I getting WA?
what I did was I considered the index of the value, which is max and its adjacent is not equal to the max element. Any test case would be helpful. Thanks
Hi, so what’s wrong in your answer is that you are considering for your answer only the next element that is at I + 1, but you also have to consider the element at i - 1 also, because it can be the case that ith element cannot eat i + 1th element but it can eat i - 1th element.
For ex:
3
2 7 7
In this case your code will output 3 as you are considering the next greater or equal element .
But its answer should be 2.
I will tell you what I did :
I printed the index of the biggest element which have different element either on (index(biggest_element)+1) or on (index(biggest_element)-1) if it is not out of bound.