Bingo Caller Judge
MediumOnline Assessment
Run a hall of bingo cards through a call sequence and report who wins each of the four prizes.
Each card is a 5x5 grid given as five rows. The centre cell (row 2, column 2) is the free space, written 0, and counts as marked from the start. Column 0 holds numbers from B (1-15), column 1 from I (16-30), column 2 from N (31-45), column 3 from G (46-60), column 4 from O (61-75). Different cards may share numbers.
The caller reads out calls such as "G52". A call is valid only if its number is from 1 to 75 and its letter is the right one for that number; a call like "B47" or "O80" is a misread and is ignored completely (no marking, no checking), but it still takes its place in the sequence. A valid call marks that number on every card that has it. A valid call for a number that was already called marks nothing new, but it is still checked.
There are four prizes, listed in this order, each awarded at most once per game:
corners: all four corner cells are marked.line: a full row, a full column, or a full diagonal.x: both diagonals are fully marked.full: all 25 cells are marked.
After each valid call, the prizes not yet awarded are examined in the order above. Each is given to every card that qualifies for it, except that a card can win only one prize per call: a card that has already been given a prize on this call is skipped for the remaining prizes (it can still win them on a later valid call while they are unclaimed). A prize that nobody qualifies for stays open.
Input: cards and calls.
Output: a list of four [step, winners] entries, one per prize in the order above. step is the 1-based position of the winning call in calls (counting ignored calls) and winners lists the winning card indices in increasing order. A prize that is never awarded is [0, []].
Example 1
- Input:
- [[[[1,16,31,46,61],[2,17,32,47,62],[3,18,0,48,63],[4,19,33,49,64],[5,20,34,50,65]],[[6,21,35,51,66],[7,22,36,52,67],[8,23,0,53,68],[9,24,37,54,69],[10,25,38,55,70]]],["B1","O61","N65","B5","O65","B6","B7","B8","B9","B10"]]
- Output:
- [[5,[0]],[10,[1]],[0,[]],[0,[]]]
- Explanation
- Cards 0 and 1 are played.
N65is a misread (65 is an O number), so it marks nothing but takes position 3. Card 0's corners (1, 61, 5, 65) are complete only whenO65is called at position 5, socornersgoes to card 0 at step 5. Calls 6-10 complete card 1's first column (6, 7, 8, 9, 10), givinglineto card 1 at step 10. Nobody getsxorfull.
Example 2
- Input:
- [[[[1,16,31,46,61],[2,17,32,47,62],[3,18,0,48,63],[4,19,33,49,64],[5,20,34,50,65]],[[2,17,32,47,62],[3,18,33,48,63],[4,19,0,49,64],[7,22,36,52,67],[5,20,34,50,65]]],["B1","O61","I20","N34","G50","B5","O65"]]
- Output:
- [[7,[0]],[7,[1]],[0,[]],[0,[]]]
- Explanation
- At call 7 (
O65) card 0 completes both its four corners and its bottom row (5, 20, 34, 50, 65), and card 1 completes the same bottom row. Cards are served prize by prize:cornersgoes to card 0, who is then skipped forlineon this call, solinegoes to card 1 alone. Card 1 has no corners, and the other prizes stay open.
Example 3
- Input:
- [[[[1,16,31,46,61],[2,17,32,47,62],[3,18,0,48,63],[4,19,33,49,64],[5,20,34,50,65]]],["B1","O61","I20","N34","G50","B5","O65","O65","I17","G99","I19","G47","B47","G49","B2","B3","B4","I16","I18","N31","N32","N33","G46","G48","O62","O63","O64"]]
- Output:
- [[7,[0]],[8,[0]],[14,[0]],[27,[0]]]
- Explanation
- At step 7 card 0 qualifies for
cornersandline; it takescorners. The repeatedO65at step 8 is a valid call that is still checked, so card 0 now takesline.G99andB47are misreads and are ignored but counted. The remaining diagonal numbers arrive by step 14 (G49), completing both diagonals, soxis awarded at step 14. The 24th distinct number,O64, is call 27, awardingfull.
Constraints
- 1 ≤ cards.length ≤ 6; each card is 5 rows of 5 integers; the centre cell is 0 and every other cell holds a distinct number from its column's range (B 1-15, I 16-30, N 31-45, G 46-60, O 61-75)
- 0 ≤ calls.length ≤ 90; each call is one of the letters B, I, N, G, O followed by an integer from 0 to 99, such as "G52"