24 Game
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an array cards of exactly four integers, each from 1 to 9. Decide whether you can combine all four numbers into an expression that equals exactly 24.
Each card must be used exactly once, in any order. You may use +, -, * and real (not integer) division /, with any placement of parentheses. You may not glue digits together (1 and 2 cannot become 12), and - is only binary (you cannot negate a single card).
Return true if some expression evaluates to 24, otherwise false.
Examples
Constraints
- `cards.length == 4`
- 1 <= cards[i] <= 9
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.