Skip to the code
cf.
+50 XP

#309 Split Tasks Into Equal Sprints

hard

A team has tasks with story points in points. The manager wants to split all tasks into exactly k sprints so that every sprint has the same total of points.

Write canSplitEvenly(points, k) that returns true if every task can be put in exactly one sprint so that all k sprint totals are equal, and false otherwise. Every point value is at least 1, so each sprint will hold at least one task.

Example 1

Input: points = [5,1,4,2,3,3], k = 3
Output: true

The total is 18, so each sprint needs 6: 5 + 1, 4 + 2, and 3 + 3.

Example 2

Input: points = [3,3,3,4], k = 2
Output: false

The total is 13, which can't be split into 2 equal whole totals.

Constraints

  • 1 <= k <= points.length <= 16
  • 1 <= points[i] <= 1000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).