-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamazon.php
More file actions
46 lines (34 loc) · 791 Bytes
/
amazon.php
File metadata and controls
46 lines (34 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
$input = array(0,1,0,2,1,0,1,3,2,1,2,1);
$volume = 0;
$temp_volume = 0;
$max_depth = max($input);
$current_level = 0;
//echo $max_depth;
foreach ($input as $key => $value) {
if ($current_level < $value) {
$current_level = $value;
$volume += $temp_volume;
//echo $temp_volume.'<br>';
$temp_volume = 0;
//echo $volume.'<br>';
}
else{
$temp_volume += ($current_level-$value);
//echo $temp_volume.'<br>';
}
}
//echo $volume.'<br>';
//echo $temp_volume.'<br>';
for($i = 0; $i < count($input): $i++){
$current_level = $input[$i];
for($j = $i+1; $j < count($input): $j++){
if ($current_level < $input[$j]) {
$current_level = $input[$j];
$volume += $temp_volume;
//echo $temp_volume.'<br>';
$temp_volume = 0;
//echo $volume.'<br>';
}
}
}