-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrisingsequence.php
More file actions
74 lines (50 loc) · 1013 Bytes
/
Copy pathrisingsequence.php
File metadata and controls
74 lines (50 loc) · 1013 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?PHP
$A = array(5, -3, -1, -10, -7, -6,100,1,-1.2);
maxRS($A);
function maxRS( $A ) {
$resultintarray=array();
$max=0;
$keymax=0;
$count=1;
$bool=true;
$lastval=$A[0];
$maxval=$val;
$newindex=0;
$len=count($A);
if(empty( $A )) exit();
for ($i=1;$i<$len;$i++) {
if($bool){$j=$i; $bool=false;} //to keep the first index in A
//check if the last value < value in A
if($lastval<=$A[$i]){
$lastval=$A[$i];
$count++;
}
else {
$resultintarray[$j]=$count;
$lastval=$A[$i];
$count=1;
$bool=true;
}
}
//get the index which had the max count
foreach ($resultintarray as $key => $val) {
//echo ($key-1).';'.$val.'<br/>';
if($val>=$maxval){
$newindex=($key-1);
$maxval=$val;
}
}
return $newindex;
}
/*for ($i = 1; $i <= 100; $i++)
{
if (!($i % 15))
echo "FizzBuzz<br/>";
else if (!($i % 3))
echo "Fizz<br/>";
else if (!($i % 5))
echo "Buzz<br/>";
else
echo "$i<br/>";
}*/
?>