#include <stdio.h>
int func(int arr[], int n)
{
if (n == 1)
return 0;
if (arr[0] >= arr[1])
return 0;
if (arr[n - 1] >= arr[n - 2])
return n - 1;
for (int i = 1; i < n - 1; i++) {
if (arr[i] >= arr[i - 1] && arr[i] >= arr[i + 1])
return i;
}
return -1;
}
int main()
{
int arr[] = { 1, 3, 20, 4, 1, 0 };
int n = sizeof(arr) / sizeof(arr[0]);
printf("Value is %d", func
(arr
, n
)); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgZnVuYyhpbnQgYXJyW10sIGludCBuKQp7CiAgICBpZiAobiA9PSAxKQogICAgICAgIHJldHVybiAwOwogICAgaWYgKGFyclswXSA+PSBhcnJbMV0pCiAgICAgICAgcmV0dXJuIDA7CiAgICBpZiAoYXJyW24gLSAxXSA+PSBhcnJbbiAtIDJdKQogICAgICAgIHJldHVybiBuIC0gMTsKCiAgICBmb3IgKGludCBpID0gMTsgaSA8IG4gLSAxOyBpKyspIHsKICAgICAgICBpZiAoYXJyW2ldID49IGFycltpIC0gMV0gJiYgYXJyW2ldID49IGFycltpICsgMV0pCiAgICAgICAgICAgIHJldHVybiBpOwogICAgfQogICAgcmV0dXJuIC0xOwp9CgppbnQgbWFpbigpCnsKICAgIGludCBhcnJbXSA9IHsgMSwgMywgMjAsIDQsIDEsIDAgfTsKICAgIGludCBuID0gc2l6ZW9mKGFycikgLyBzaXplb2YoYXJyWzBdKTsKICAgIHByaW50ZigiVmFsdWUgaXMgJWQiLCBmdW5jKGFyciwgbikpOwogICAgcmV0dXJuIDA7Cn0=