Skip to content

ORIGINAL CODING QUESTION

Even workload split

A lead must hand every one of n tasks, each with a positive effort, to exactly one of two squads. Print 1 if the squads can end up with equal total effort, otherwise 0.

Open practice workspace

Original exercise · medium. Editorial role relevance does not imply a company has asked this question.

Input and output

n, then n task efforts.

Constraints

1 ≤ n ≤ 12; 1 ≤ effort ≤ 100.

Example 1

Input

4 3 1 1 5

Output

1

Efforts 3, 1 and 1 balance the single 5.

Example 2

Input

3 2 3 4

Output

0

The total 9 is odd, so no equal split exists.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

An odd total can never be split evenly.

Hint 2

Otherwise ask whether some subset reaches exactly half the total.

Hint 3

Track reachable sums in a boolean table, updating from high sums to low.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →