Skip to main content

Practice · 5 of 5

Present Bags

CHALLENGE
Difficulty: intermediate+25 XP

**Description:** n bags; bag i contains a[i] candies. Split the bags into two groups so that the difference of total candies between groups is minimized. Print that minimum difference. n is small — full search is intended. **Input:** Line 1: n (1 <= n <= 20). Line 2: n integers (1 <= a[i] <= 10^6). **Output:** One integer — the minimal |sum1 - sum2|. **Example:** 3 / 1 2 4 -> 1 (1+2=3 vs 4).

Back to lesson: Practice: Mixed Mock Problems