FastPrepHungarian Lottery Winner Counts
Problems/Hungarian Lottery Winner Counts

Hungarian Lottery Winner Counts

Alpaca logoAlpaca● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The judged task preserves the reported Hungarian lottery rules and winner-count query. The callable input format is authored for practice, and the core task matches the visible source at about 98%.

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

  • Make a Sorted Array Unique In PlaceONSITE INTERVIEW · Seen Aug 2026
  • Return Distinct ElementsPHONE SCREEN · Seen Aug 2026
  • Aggregate a Large Dataset With GROUP BYPHONE SCREEN · Seen Sep 2022
See Alpaca hiring insights
Saved
class Solution {
    public int[] countLotteryMatches(int[][] tickets, int[] drawn) {
        // Write your code here.
    }
}
Checking account…