3v4l.org

run code in 300+ PHP versions simultaneously
<?php function solution($A) { $n = sizeof($A); $result = 0; for ($i = 0; $i < $n - 1; $i++) { if ($A[$i] == $A[$i + 1]) $result = $result + 1; } $r = 0; for ($i = 0; $i < $n; $i++) { $count = 0; if ($i > 0) { if ($A[$i - 1] != $A[$i]) $count = $count + 1; else $count = $count - 1; } if ($i < $n - 1) { if ($A[$i + 1] != $A[$i]) $count = $count + 1; else $count = $count - 1; } $r = max($r, $count); } return $result + $r; } $A[0] = 1; $A[1] = 1; $A[2] = 0; $A[3] = 1 ; $A[4] = 0 ; $A[5] = 0; print_r(solution($A));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bjf72
function name:  (null)
number of ops:  19
compiled vars:  !0 = $A
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ASSIGN_DIM                                               !0, 0
          1        OP_DATA                                                  1
   32     2        ASSIGN_DIM                                               !0, 1
          3        OP_DATA                                                  1
   33     4        ASSIGN_DIM                                               !0, 2
          5        OP_DATA                                                  0
   34     6        ASSIGN_DIM                                               !0, 3
          7        OP_DATA                                                  1
   35     8        ASSIGN_DIM                                               !0, 4
          9        OP_DATA                                                  0
   36    10        ASSIGN_DIM                                               !0, 5
         11        OP_DATA                                                  0
   39    12        INIT_FCALL                                               'print_r'
         13        INIT_FCALL                                               'solution'
         14        SEND_VAR                                                 !0
         15        DO_FCALL                                      0  $7      
         16        SEND_VAR                                                 $7
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Function solution:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 6
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 20
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 33
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 46
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 20
Branch analysis from position: 54
Branch analysis from position: 20
Branch analysis from position: 44
2 jumps found. (Code = 44) Position 1 = 54, Position 2 = 20
Branch analysis from position: 54
Branch analysis from position: 20
Branch analysis from position: 46
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 46
Branch analysis from position: 36
Branch analysis from position: 46
Branch analysis from position: 33
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 6
Branch analysis from position: 17
Branch analysis from position: 6
Branch analysis from position: 13
filename:       /in/bjf72
function name:  solution
number of ops:  57
compiled vars:  !0 = $A, !1 = $n, !2 = $result, !3 = $i, !4 = $r, !5 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        COUNT                                            ~6      !0
          2        ASSIGN                                                   !1, ~6
    5     3        ASSIGN                                                   !2, 0
    6     4        ASSIGN                                                   !3, 0
          5      > JMP                                                      ->14
    7     6    >   FETCH_DIM_R                                      ~10     !0, !3
          7        ADD                                              ~11     !3, 1
          8        FETCH_DIM_R                                      ~12     !0, ~11
          9        IS_EQUAL                                                 ~10, ~12
         10      > JMPZ                                                     ~13, ->13
    8    11    >   ADD                                              ~14     !2, 1
         12        ASSIGN                                                   !2, ~14
    6    13    >   PRE_INC                                                  !3
         14    >   SUB                                              ~17     !1, 1
         15        IS_SMALLER                                               !3, ~17
         16      > JMPNZ                                                    ~18, ->6
   10    17    >   ASSIGN                                                   !4, 0
   11    18        ASSIGN                                                   !3, 0
         19      > JMP                                                      ->52
   12    20    >   ASSIGN                                                   !5, 0
   13    21        IS_SMALLER                                               0, !3
         22      > JMPZ                                                     ~22, ->33
   14    23    >   SUB                                              ~23     !3, 1
         24        FETCH_DIM_R                                      ~24     !0, ~23
         25        FETCH_DIM_R                                      ~25     !0, !3
         26        IS_NOT_EQUAL                                             ~24, ~25
         27      > JMPZ                                                     ~26, ->31
   15    28    >   ADD                                              ~27     !5, 1
         29        ASSIGN                                                   !5, ~27
         30      > JMP                                                      ->33
   17    31    >   SUB                                              ~29     !5, 1
         32        ASSIGN                                                   !5, ~29
   19    33    >   SUB                                              ~31     !1, 1
         34        IS_SMALLER                                               !3, ~31
         35      > JMPZ                                                     ~32, ->46
   20    36    >   ADD                                              ~33     !3, 1
         37        FETCH_DIM_R                                      ~34     !0, ~33
         38        FETCH_DIM_R                                      ~35     !0, !3
         39        IS_NOT_EQUAL                                             ~34, ~35
         40      > JMPZ                                                     ~36, ->44
   21    41    >   ADD                                              ~37     !5, 1
         42        ASSIGN                                                   !5, ~37
         43      > JMP                                                      ->46
   23    44    >   SUB                                              ~39     !5, 1
         45        ASSIGN                                                   !5, ~39
   25    46    >   INIT_FCALL                                               'max'
         47        SEND_VAR                                                 !4
         48        SEND_VAR                                                 !5
         49        DO_ICALL                                         $41     
         50        ASSIGN                                                   !4, $41
   11    51        PRE_INC                                                  !3
         52    >   IS_SMALLER                                               !3, !1
         53      > JMPNZ                                                    ~44, ->20
   27    54    >   ADD                                              ~45     !2, !4
         55      > RETURN                                                   ~45
   28    56*     > RETURN                                                   null

End of function solution

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.11 ms | 1406 KiB | 18 Q