1 / 3
Aug 2022

Hi, I’m trying to solve BEADS - Glass Beads in PHP, in my IDE it works, but when I’m trying to submit to spoj I do get an error wrong. Please some help would be appreciated.
Edit:
Fixed the input stuck at a max time limit :man_facepalming:

fscanf(STDIN, “%d\n”, $n);
$testCases = [];
for ($i = 0; $i < $n; $i++) {
fscanf(STDIN, “%s\n”, $strings);
$testCases[] = $strings;
}

$valuesOfLowestLexi = 0;

function check($case, $valuesOfLowestLexi, $iteration, $n)
{
for ($i = 0; $i < $n; $i++) {
if ($case[$valuesOfLowestLexi] < $case[$iteration]) {
return false;
} else {
if ($case[$valuesOfLowestLexi] > $case[$iteration]) {
return true;
}
}

    $valuesOfLowestLexi = ($valuesOfLowestLexi + 1) % $n;


    $iteration = ($iteration + 1) % $n;
}
return true;

}

foreach ($testCases as $case) {
for ($i = 1; $i < strlen($case); $i++) {
if (check($case, $valuesOfLowestLexi, $i, strlen($case))) {
$valuesOfLowestLexi = $i;
}
}
echo $valuesOfLowestLexi + 1 . PHP_EOL;
}

  • created

    Aug '22
  • last reply

    Aug '22
  • 2

    replies

  • 437

    views

  • 2

    users

  • 1

    link

When I run your code on IDEONE with the sample input from the problem, it gives

1
1
1
1
1

Does it work for you on IDEONE?