fork download
  1. #include <stdio.h>
  2.  
  3. int func(int arr[], int n)
  4. {
  5. if (n == 1)
  6. return 0;
  7. if (arr[0] >= arr[1])
  8. return 0;
  9. if (arr[n - 1] >= arr[n - 2])
  10. return n - 1;
  11.  
  12. for (int i = 1; i < n - 1; i++) {
  13. if (arr[i] >= arr[i - 1] && arr[i] >= arr[i + 1])
  14. return i;
  15. }
  16. return -1;
  17. }
  18.  
  19. int main()
  20. {
  21. int arr[] = { 1, 3, 20, 4, 1, 0 };
  22. int n = sizeof(arr) / sizeof(arr[0]);
  23. printf("Value is %d", func(arr, n));
  24. return 0;
  25. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Value is 2