Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php //Прямой перебор function alg(array $arr) : int { $sum = 0; $j = 0; $count = 0; while($count <= count($arr) - 1 ){ $max = 0; for ($i = $j; $i <= count($arr) - 1; $i++ ){ if($arr[$i] > $max){ $max = $arr[$i]; $j = $i; } } $sum = $max * ($j + 1 - $count); $count = $i; } return end($arr); } $arr = [1, 3, 1, 2]; echo alg($arr);
Copy Clear