Class Solution
java.lang.Object
g2501_2600.s2522_partition_string_into_substrings_with_values_at_most_k.Solution
2522 - Partition String Into Substrings With Values at Most K.<p>Medium</p>
<p>You are given a string <code>s</code> consisting of digits from <code>1</code> to <code>9</code> and an integer <code>k</code>.</p>
<p>A partition of a string <code>s</code> is called <strong>good</strong> if:</p>
<ul>
<li>Each digit of <code>s</code> is part of <strong>exactly</strong> one substring.</li>
<li>The value of each substring is less than or equal to <code>k</code>.</li>
</ul>
<p>Return <em>the <strong>minimum</strong> number of substrings in a <strong>good</strong> partition of</em> <code>s</code>. If no <strong>good</strong> partition of <code>s</code> exists, return <code>-1</code>.</p>
<p><strong>Note</strong> that:</p>
<ul>
<li>The <strong>value</strong> of a string is its result when interpreted as an integer. For example, the value of <code>"123"</code> is <code>123</code> and the value of <code>"1"</code> is <code>1</code>.</li>
<li>A <strong>substring</strong> is a contiguous sequence of characters within a string.</li>
</ul>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “165462”, k = 60</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> 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.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “238182”, k = 5</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> There is no good partition for this string.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
<li><code>s[i]</code> is a digit from <code>'1'</code> to <code>'9'</code>.</li>
<li><code>1 <= k <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumPartition
-