+ 1
help please 😢
An array containing 5 non-negative integers is given. A pit is a non-edge element of an array that is smaller than both of its neighbors. It is necessary to find the deepest pit in the array, that is, the pit whose value is minimal. If there is no pit in the array, the answer is considered equal to 0. For example, in an array of six elements equal to 4, 9, 2, 17, 3, 8, respectively, there are two pits - 2 and 3, the deepest pit - 2. I have two solutions. I wrote the first myself. The second solution is the real answer to this problem. Tell me whether my solution (version 1) is suitable for this task or not https://code.sololearn.com/cq1ef3tOWL1P/?ref=app
3 odpowiedzi
+ 1
🤕
+ 1
Your code fails for [1, 4, 2, 4, 1]. The expected output is 2, yours is 1.
Hint: What happens if the first element, namely "a[0]", is less than all of the pits?
0
The answer is "aaa".