The number of goals achieved by two football teams in matches in a league is given in the form of two lists. For each match of team B, compute the total number of matches of team A where team A has scored less than or equal to the number of goals team B has scored in a match
Example
TeamA = [1,2,3]
Team B = [2,4]
team A has played 3 matches and has scored TeamA = [1,2,3] goals in each match respectively. Team B has played two matches and has scored teamB = [2,4] in each match respectively. For two goals scored by teamB in its first match team A has two matches with 1 and 2 score. For four goals scored by teamB in its second match team A has three matches with 1, 2 and 3 score.
Hence the answer is [2,3]
the main editing should be done only in the function please.
how do I go about it.
<?php
function counts($teamA, $teamB) {
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$teamA_count = intval(trim(fgets(STDIN)));
$teamA = array();
for ($i = 0; $i < $teamA_count; $i++) {
$teamA_item = intval(trim(fgets(STDIN)));
$teamA[] = $teamA_item;
}
$teamB_count = intval(trim(fgets(STDIN)));
$teamB = array();
for ($i = 0; $i < $teamB_count; $i++) {
$teamB_item = intval(trim(fgets(STDIN)));
$teamB[] = $teamB_item;
}
$result = counts($teamA, $teamB);
fwrite($fptr, implode("\n", $result) . "\n");
fclose($fptr);
If anything is needed let me know
Top comments (0)