<p>You are given three integers <code>start</code>, <code>finish</code>, and <code>limit</code>. You are also given a <strong>0-indexed</strong> string <code>s</code> representing a <strong>positive</strong> integer.</p>

<p>A <strong>positive</strong> integer <code>x</code> is called <strong>powerful</strong> if it ends with <code>s</code> (in other words, <code>s</code> is a <strong>suffix</strong> of <code>x</code>) and each digit in <code>x</code> is at most <code>limit</code>.</p>

<p>Return <em>the <strong>total</strong> number of powerful integers in the range</em> <code>[start..finish]</code>.</p>

<p>A string <code>x</code> is a suffix of a string <code>y</code> if and only if <code>x</code> is a substring of <code>y</code> that starts from some index (<strong>including </strong><code>0</code>) in <code>y</code> and extends to the index <code>y.length - 1</code>. For example, <code>25</code> is a suffix of <code>5125</code> whereas <code>512</code> is not.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> start = 1, finish = 6000, limit = 4, s = &quot;124&quot;
<strong>Output:</strong> 5
<strong>Explanation:</strong> The powerful integers in the range [1..6000] are 124, 1124, 2124, 3124, and, 4124. All these integers have each digit &lt;= 4, and &quot;124&quot; as a suffix. Note that 5124 is not a powerful integer because the first digit is 5 which is greater than 4.
It can be shown that there are only 5 powerful integers in this range.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> start = 15, finish = 215, limit = 6, s = &quot;10&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> The powerful integers in the range [15..215] are 110 and 210. All these integers have each digit &lt;= 6, and &quot;10&quot; as a suffix.
It can be shown that there are only 2 powerful integers in this range.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> start = 1000, finish = 2000, limit = 4, s = &quot;3000&quot;
<strong>Output:</strong> 0
<strong>Explanation:</strong> All integers in the range [1000..2000] are smaller than 3000, hence &quot;3000&quot; cannot be a suffix of any integer in this range.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= start &lt;= finish &lt;= 10<sup>15</sup></code></li>
	<li><code>1 &lt;= limit &lt;= 9</code></li>
	<li><code>1 &lt;= s.length &lt;= floor(log<sub>10</sub>(finish)) + 1</code></li>
	<li><code>s</code> only consists of numeric digits which are at most <code>limit</code>.</li>
	<li><code>s</code> does not have leading zeros.</li>
</ul>

from typing import List  

class Solution:  
    def numberOfPowerfulInt(self, start: int, finish: int, l: int, s: str) -> int:  
        # Initialize a count array for the number of powerful integers of different lengths  
        count_array = [0] * 16  

        def calculate_powerful_count(num_str: str, str_condition: str) -> int:  
            # Initialize result with the count of powerful integers of the same length  
            result = count_array[len(num_str) - 1]  
            size = len(num_str) - len(str_condition)  

            # Iterate through the digits of num_str using enumerate  
            for index, digit in enumerate(num_str):  
                # Check the current digit and update result  
                if index == size:  
                    result += (num_str[index:] >= str_condition)  
                else:  
                    result += count_array[len(num_str) - index - 1] * (min(l, int(digit) - 1) + (index > 0))  

                # Break conditions for the loop  
                if index > size or int(digit) > l:  
                    break  

            return result  

        # Precompute the counts for different lengths, up to 15 digits  
        for length in range(len(s), 16):  
            count_array[length] = 1 if length == len(s) else count_array[length - 1] * (l + 1)  

        # Return the difference in counts between finish and start  
        return calculate_powerful_count(str(finish), s) - calculate_powerful_count(str(start - 1), s)  

    def is_powerful_integer(self, number: int, l: int, s: str) -> bool:  
        """Check if the integer number is a powerful integer."""  
        # Convert number to string for comparison  
        number_str = str(number)  
        return number_str >= s and all(int(digit) <= l for digit in number_str)  

    def generate_powerful_integers(self, start: int, finish: int, l: int, s: str) -> List[int]:  
        """Generate a list of powerful integers within the range [start, finish]."""  
        powerful_ints = []  
        for number in range(start, finish + 1):  
            if self.is_powerful_integer(number, l, s):  
                powerful_ints.append(number)  
        return powerful_ints
46