812. 24 Game (All Expressions with 4 Numbers)

HardRecursionRecursion

Given 4 positive integers (1-13, representing cards), determine if any combination of +,-,*,/ and parentheses can produce exactly 24. Each number used exactly once. Return true/false.

Input: An array of 4 integers.

Output: Boolean.

Examples

Example 1
Input: [1,2,3,4]
Output: true
Explanation: 1*2*3*4=24.
Example 2
Input: [1,1,1,1]
Output: false
Explanation: No way to make 24.

Constraints

Asked by

GoogleMicrosoftBloombergMeta
Solve this problem in the editor →