FastPrepValidate a Mahjong Hand Partition
Problems/Validate a Mahjong Hand Partition

Validate a Mahjong Hand Partition

Duolingo logoDuolingo● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This practice problem preserves the reported digits 1–9, exactly one pair, arbitrary triples and consecutive runs, the example 11123456, and the backtracking objective; only finite bounds are added.

A Mahjong-like hand is represented by an unordered array tiles whose values are digits from 1 through 9.

Return whether every tile can be partitioned into:

  • exactly one pair of equal values (the pair of eyes); and
  • zero or more three-tile groups, where each group is either three equal values or three consecutive values x, x + 1, x + 2.

Every tile occurrence must belong to exactly one group. The order of tiles in the input does not matter.

Function

isValidMahjongHand(tiles: int[]) → boolean

Examples

Example 1

tiles = [1,1,1,2,3,4,5,6]return = true

Use [1,1] as the pair, then form the runs [1,2,3] and [4,5,6].

Example 2

tiles = [1,1,1,2,2]return = true

The hand partitions into the triple [1,1,1] and the pair [2,2].

Example 3

tiles = [1,1,1,1,2]return = false

The only way to pick a pair is two of the four ones. That leaves one, one and two. These are not three equal tiles and not three tiles in a row, so the hand is not valid.

Constraints

  • 2 <= tiles.length <= 20.
  • Every tile value is between 1 and 9.
  • A valid hand always has 3g + 2 tiles for some g >= 0, so a hand of any other length is not valid.

More Duolingo Phone Screen questions

  • Group Timestamps into Consecutive-Day IntervalsPHONE SCREEN · Seen Nov 2026
  • Return Every Matching DecryptionPHONE SCREEN · Seen Nov 2026
  • Visit Desired Attractions Without Reusing a TrailPHONE SCREEN · Seen Oct 2026
  • Correct an In-Place Array ReversalPHONE SCREEN · Seen Oct 2026
  • Count Starts Reaching a Grid MaximumPHONE SCREEN · Seen Oct 2026
  • Select the Top User MatchesPHONE SCREEN · Seen Oct 2026
  • Sum All Values in a Binary TreePHONE SCREEN · Seen Oct 2026
  • User Resource Transition ProbabilitiesPHONE SCREEN · Seen Oct 2026
  • Encrypt and Decrypt StringsPHONE SCREEN · Seen Apr 2026
  • Directional Tiles: Find a Valid Reconfiguration PathPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • Combination Sum with Reusable ValuesPinterest · PHONE SCREENPinterest interview questions
  • All Subsets with a Given SumApple · PHONE SCREENApple interview questions
  • Construct a Tree from Level-Order and Inorder TraversalsAmazon · PHONE SCREEN
  • Optimal Account BalancingSalesforce · PHONE SCREENSalesforce interview questions
  • Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Minimum Account SettlementsRippling · PHONE SCREENRippling interview questions
  • Combination Sum With Unlimited ReuseMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • All Subsequences with Sum KExpedia · ONSITE INTERVIEWExpedia interview questions
  • Optimal Account BalancingVirtu Financial · OAVirtu Financial interview questions
  • Count Complete Tic-Tac-Toe GamesDecagon · PHONE SCREEN · ONSITE INTERVIEWDecagon interview questions

Interview reports that mention this question

  • Duolingo SWE Interview Questions: 3 Experiences

Duolingo interview experiences

  • Duolingo interviews · November 2026
All Duolingo interview questionsSee Duolingo hiring insights
Saved
class Solution {
    public boolean isValidMahjongHand(int[] tiles) {
        // write your code here
    }
}
Checking account…