Coding problem
Split into two equal totals
The task
Two delivery drivers share a day's parcels, and the planner wants both vans to carry exactly the same total weight.
Complete CanSplitEqually(int[] values). The values are 0 or more. Return true if every value can be put in one of two groups so that both groups have the same sum, otherwise false. A group may be empty, so an empty array can be split.
Signature
public static bool CanSplitEqually(int[] values)
Examples
[4, 2, 6, 3, 3]→true. 4 + 2 + 3 = 6 + 3 = 9.[1, 3, 8]→false. The total, 12, is even, but no group adds up to 6.
Limits: Up to 200 values, each from 0 to 1,000.
The tests check: no values, two equal and two different values, one value, zeros, an odd total, an even total that cannot split, repeated values, and 200 values with and without a split in time.
Hints
Your code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public static class Solution
{
// True when the values can form two groups with equal sums.
public static bool CanSplitEqually(int[] values)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.