data-structures · intermediate · ~15 min
Decide if an array splits into two equal-sum halves.
Implement:
int can_partition(const int *a, int n);
Return 1 if the non-negative array can be split into two subsets with equal sums, else 0.
Non-negative a, count n.
1 if an equal split exists, else 0.
a is array of n positive integers.
#include <stddef.h>
/* Return 1 if a[0..n-1] (non-negative) can be split into two subsets with equal sums, else 0. */
int can_partition(const int *a,int n){ (void)a;(void)n; return 0; }
Assuming sorted array or integer overflow on total sum.
Odd sum (impossible), empty array, single element, partition exists.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.