digikala_challenge
digikala interview code challengeunknown
php
10 months ago
361 B
9
Indexable
<?php
$arr = [10, 3, 5, 6, 2];
$count = count($arr);
$prod = [];
for ($i = 0; $i < $count; $i++) {
$prod[$i] = 1;
}
$left = 1;
for ($i = 0; $i < $count; $i++) {
$prod[$i] = $left;
$left = $left * $arr[$i];
}
$right = 1;
for ($i = $count - 1; $i >= 0; $i--) {
$prod[$i] = $prod[$i] * $right;
$right = $right * $arr[$i];
}
print_r($prod);Editor is loading...
Leave a Comment