Function for finding a peak in an array
Swift
Medium
functions
Task «Function for finding a peak in an array»
Write a function that takes an array of integers and returns the index of the peak. A peak is considered an element that is strictly greater than its neighbors. If the array contains multiple peaks, return the index of the first one. If the array is empty or contains fewer than 3 elements, return -1. The function must be implemented without using built-in search methods.
Input Format
The input is a string of integers separated by spaces.
Output Format
One integer — the index of the first peak, or -1 if no peak is found.
Examples
Example 1
INPUT
5 4 3 2 1
OUTPUT
-1
main.swift