Class Solution
-
- All Implemented Interfaces:
public final class Solution2522 - Partition String Into Substrings With Values at Most K.
Medium
You are given a string
sconsisting of digits from1to9and an integerk.A partition of a string
sis called good if:Each digit of
sis part of exactly one substring.The value of each substring is less than or equal to
k.
Return the minimum number of substrings in a good partition of
s. If no good partition ofsexists, return-1.Note that:
The value of a string is its result when interpreted as an integer. For example, the value of
"123"is123and the value of"1"is1.A substring is a contiguous sequence of characters within a string.
Example 1:
Input: s = "165462", k = 60
Output: 4
Explanation: We can partition the string into substrings "16", "54", "6", and "2". Each substring has a value less than or equal to k = 60. It can be shown that we cannot partition the string into less than 4 substrings.
Example 2:
Input: s = "238182", k = 5
Output: -1
Explanation: There is no good partition for this string.
Constraints:
<code>1 <= s.length <= 10<sup>5</sup></code>
s[i]is a digit from'1'to'9'.<code>1 <= k <= 10<sup>9</sup></code>
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntegerminimumPartition(String s, Integer k)-
-
Method Detail
-
minimumPartition
final Integer minimumPartition(String s, Integer k)
-
-
-
-