Class Solution

java.lang.Object
g1401_1500.s1416_restore_the_array.Solution

public class Solution extends Object
1416 - Restore The Array.<p>Hard</p> <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits <code>s</code> and all we know is that all integers in the array were in the range <code>[1, k]</code> and there are no leading zeros in the array.</p> <p>Given the string <code>s</code> and the integer <code>k</code>, return <em>the number of the possible arrays that can be printed as</em> <code>s</code> <em>using the mentioned program</em>. Since the answer may be very large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;1000&rdquo;, k = 10000</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The only possible array is [1000]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;1000&rdquo;, k = 10</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> There cannot be an array that was printed this way and has all integer >= 1 and <= 10.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;1317&rdquo;, k = 2000</p> <p><strong>Output:</strong> 8</p> <p><strong>Explanation:</strong> Possible arrays are [1317],[131,7],[13,17],[1,317],[13,1,7],[1,31,7],[1,3,17],[1,3,1,7]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>s</code> consists of only digits and does not contain leading zeros.</li> <li><code>1 <= k <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numberOfArrays

      public int numberOfArrays(String s, int k)