Fair Division Problem - Problem
You need to divide N items with integer values between two people so that the absolute difference in their total values is minimized.
Given an array values where values[i] represents the value of the i-th item, return the minimum possible absolute difference between the two groups' totals.
Example: If items have values [1, 6, 11, 5], one optimal division is {1, 5} and {6, 11}, giving totals of 6 and 17, with absolute difference |6 - 17| = 11.
Input & Output
Example 1 — Basic Case
$
Input:
values = [1, 6, 11, 5]
›
Output:
1
💡 Note:
Optimal division: {6, 5} with sum 11 and {1, 11} with sum 12. Absolute difference = |11 - 12| = 1.
Example 2 — Perfect Split
$
Input:
values = [1, 1, 3, 5]
›
Output:
0
💡 Note:
Perfect division: {1, 5} and {1, 3} both have sum 6. Absolute difference = |6 - 6| = 0.
Example 3 — Single Item
$
Input:
values = [100]
›
Output:
100
💡 Note:
One person gets the item (100), the other gets nothing (0). Difference = |100 - 0| = 100.
Constraints
- 1 ≤ values.length ≤ 20
- 1 ≤ values[i] ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code