fork download
  1. <?php
  2.  
  3. $numbers = [1, 2, 1, 4, 1];
  4.  
  5. for ($i = 0; $i < count($numbers); $i += 1) {
  6. $highest = -1;
  7.  
  8. for ($j = 0; $j < count($numbers); $j += 1) {
  9. $candidate = $numbers[($i + $j) % count($numbers)];
  10.  
  11. if ($candidate > $numbers[$i] && $candidate > $highest) {
  12. $highest = $candidate;
  13. break;
  14. }
  15. }
  16.  
  17. echo $highest . PHP_EOL;
  18. }
Success #stdin #stdout 0s 82560KB
stdin
Standard input is empty
stdout
2
4
4
-1
2