Separate the numbers

Here is a question that i am stuck at
Given a number in form of a string, the task is to seperate string into individual digits by applying the following operation:

  • Select part of the string (if and only if sum of digits > 17) and insert a space between in it.

Example:
11 -> sum of digits is less than 17, so can’t splint
399 -> [3,99] -> [3,9,9] //can split
9944 -> [994,4] -> [99,4,4] -> [9,9,4,4] //can split

Find the prefix sum array and find left and right indices such that prefix[right] - prefix[left-1] > 17.

These indices will be the end points of the substring to split.