fork download
  1. <?php
  2.  
  3.  
  4. $memoryLeng = 0;
  5. $memoryNumber = 0;
  6. $array = array();
  7. for ($i=0; $i<=19; $i++) {
  8. $random = mt_rand(0,1);
  9. $array{$i}=$random;
  10. }
  11. print_r($array);
  12. foreach ($array as $value) {
  13. if ($value == 0) {
  14. $leng++;
  15. $number=$value;
  16. if ($leng > $memoryLeng) { //если длина окажется больше длины в памяти - сохраняем новую длину
  17. $memoryLeng=$leng;
  18. $memoryNumber=$number+1-$memoryLeng;
  19. }
  20. } else {
  21. $leng=0;
  22. }
  23. }
  24. echo "{$memoryLeng}\n {$memoryNumber}";
  25.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 1
    [1] => 1
    [2] => 1
    [3] => 0
    [4] => 1
    [5] => 1
    [6] => 1
    [7] => 0
    [8] => 0
    [9] => 1
    [10] => 0
    [11] => 1
    [12] => 1
    [13] => 0
    [14] => 1
    [15] => 1
    [16] => 0
    [17] => 1
    [18] => 0
    [19] => 0
)
2
 -1