DEV Community

loading...

Discussion on: Daily Challenge #306 - Largest Possible Product

Collapse
gugod profile image
Kang-min Liu

Perl

sub adjacentProduct {
    my @nums = @{ $_[0] };
    my $max = 0;
    for my $i (0..@nums-2) {
        my $p = $nums[$i] * $nums[$i+1];
        $max = $p if $max < $p;
    }
    return $max;
}

Enter fullscreen mode Exit fullscreen mode