Given an array of unique elements = [ 2, 6, 11, 21, 5 ]. How can I write an O(1) algorithm that returns an element that is not the smallest in the array?
// I tried... but not sure if this is O(1) - runtime
$arr = [2, 6, 11, 21, 5];
$smallest = $arr[0];
function returnSmallest() {
for( i = 1; i < $arr.length; i++ )
{
if($arr[i] < $smallest)
{
$smallest = $arr[i];
}
} return $smallest;
}();
print($smallest);