digits of the digits 1 through 9 and an integer cap. Cut the string into consecutive pieces; the value of a piece is the number it spells out (for instance, the piece "35" has value 35).
Every piece must have a value of at most cap. Return the smallest possible number of pieces, or -1 if no such cut exists.digits="381927", cap=50 → 3
For example "38", "19", "27": every value is at most 50. Two pieces are impossible, since one of them would have three digits.
digits="472", cap=6 → -1
The digit 7 alone already exceeds 6, so no valid cut exists.
digits="1111", cap=1111 → 1
digits is a digit from 1 to 9digits="381927", cap=50
3
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.