Find max element in increasing-decreasing array
Your code will segfault for array size = 2. Rest looks correct to me.

Specifically, for size = 2,

left = 0
right = 1
mid = 0


And hence, this line:

if (arr[mid] &gt; arr[mid-1] &amp;&amp; arr[mid] &gt; arr[mid+1])


will try to access arr[mid-1] which is arr[-1] and can segfault/return incorrect answer.