Loading...
You are given a string s consisting of digits '1' to '9', and an integer k.
Split s into contiguous substrings so that:
s belongs to exactly one substring, andk.Return the minimum number of substrings in such a split, or -1 if no valid split exists.
Input: s = "165462", k = 60
Output: 4
Explanation: Splitting into "16", "54", "6", "2" keeps every value at most 60, and no split with fewer than 4 substrings works.
Input: s = "238182", k = 5
Output: -1
Explanation: The digit 8 alone already exceeds 5, so no valid split exists.
s.length ≤105s[i] is a digit from '1' to '9'k ≤109Click "Run" to test with sample cases or "Submit" to run all tests.