FastPrepHungarian Lottery Winner Counts

Hungarian Lottery Winner Counts

Alpaca logoAlpaca● MediumFULLTIMEOA
Learn

Problem statement

Players submit lottery tickets containing five distinct numbers. Given all submitted tickets and the five drawn numbers, count how many tickets match exactly two, three, four, and five drawn numbers.

Return the four counts in that order: [matches2, matches3, matches4, matches5].

Function

countLotteryMatches(tickets: int[][], drawn: int[]) → int[]

Examples

Example 1

tickets = [[1,2,3,4,5],[1,2,6,7,8],[1,2,3,9,10],[11,12,13,14,15]]drawn = [1,2,3,4,5]return = [1,1,0,1]

The four tickets match exactly five, two, three, and zero drawn numbers.

Example 2

tickets = [[1,2,3,4,5],[5,4,3,2,1]]drawn = [1,2,3,4,5]return = [0,0,0,2]

Ticket order does not matter; both tickets match all five numbers.

Example 3

tickets = []drawn = [1,2,3,4,5]return = [0,0,0,0]

No submitted tickets means no winners in any prize tier.

Constraints

  • 0 ≤ tickets.length ≤ 10^7.
  • Every ticket and drawn contain five distinct integers from 1 through 90.
  • The input fits in memory.

More Alpaca problems

See Alpaca hiring insights
public int[] countLotteryMatches(int[][] tickets, int[] drawn) {
    // Write your code here.
}
tickets[[1,2,3,4,5],[1,2,6,7,8],[1,2,3,9,10],[11,12,13,14,15]]
drawn[1,2,3,4,5]
expected[1,1,0,1]
Checking account…