java.lang.Object
g2501_2600.s2575_find_the_divisibility_array_of_a_string.Solution

public class Solution extends Object
2575 - Find the Divisibility Array of a String.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> string <code>word</code> of length <code>n</code> consisting of digits, and a positive integer <code>m</code>.</p> <p>The <strong>divisibility array</strong> <code>div</code> of <code>word</code> is an integer array of length <code>n</code> such that:</p> <ul> <li><code>div[i] = 1</code> if the <strong>numeric value</strong> of <code>word[0,...,i]</code> is divisible by <code>m</code>, or</li> <li><code>div[i] = 0</code> otherwise.</li> </ul> <p>Return <em>the divisibility array of</em> <code>word</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> word = &ldquo;998244353&rdquo;, m = 3</p> <p><strong>Output:</strong> [1,1,0,0,0,1,1,0,0]</p> <p><strong>Explanation:</strong> There are only 4 prefixes that are divisible by 3: &ldquo;9&rdquo;, &ldquo;99&rdquo;, &ldquo;998244&rdquo;, and &ldquo;9982443&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> word = &ldquo;1010&rdquo;, m = 10</p> <p><strong>Output:</strong> [0,1,0,1]</p> <p><strong>Explanation:</strong> There are only 2 prefixes that are divisible by 10: &ldquo;10&rdquo;, and &ldquo;1010&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 10<sup>5</sup></code></li> <li><code>word.length == n</code></li> <li><code>word</code> consists of digits from <code>0</code> to <code>9</code></li> <li><code>1 <= m <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • divisibilityArray

      public int[] divisibilityArray(String word, int m)