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.
Only possible when the total is even.
#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; }
Not short-circuiting on an odd total (there is no half to hit).
Odd total -> 0.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.