<p>You are given a <strong>0-indexed</strong> string <code>num</code> representing a non-negative integer.</p>

<p>In one operation, you can pick any digit of <code>num</code> and delete it. Note that if you delete all the digits of <code>num</code>, <code>num</code> becomes <code>0</code>.</p>

<p>Return <em>the <strong>minimum number of operations</strong> required to make</em> <code>num</code> <i>special</i>.</p>

<p>An integer <code>x</code> is considered <strong>special</strong> if it is divisible by <code>25</code>.</p>

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

<pre>
<strong>Input:</strong> num = &quot;2245047&quot;
<strong>Output:</strong> 2
<strong>Explanation:</strong> Delete digits num[5] and num[6]. The resulting number is &quot;22450&quot; which is special since it is divisible by 25.
It can be shown that 2 is the minimum number of operations required to get a special number.</pre>

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

<pre>
<strong>Input:</strong> num = &quot;2908305&quot;
<strong>Output:</strong> 3
<strong>Explanation:</strong> Delete digits num[3], num[4], and num[6]. The resulting number is &quot;2900&quot; which is special since it is divisible by 25.
It can be shown that 3 is the minimum number of operations required to get a special number.</pre>

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

<pre>
<strong>Input:</strong> num = &quot;10&quot;
<strong>Output:</strong> 1
<strong>Explanation:</strong> Delete digit num[0]. The resulting number is &quot;0&quot; which is special since it is divisible by 25.
It can be shown that 1 is the minimum number of operations required to get a special number.

</pre>

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

<ul>
	<li><code>1 &lt;= num.length &lt;= 100</code></li>
	<li><code>num</code> only consists of digits <code>&#39;0&#39;</code> through <code>&#39;9&#39;</code>.</li>
	<li><code>num</code> does not contain any leading zeros.</li>
</ul>

class Solution:
    def minimumOperations(self, num: str) -> int:
        n = len(num)
        
        # Helper function to find the last occurrence of a digit before a given index
        def find_last(digit, end_index=n-1):
            return num.rfind(digit, 0, end_index + 1)
        
        # Special case: if the number is already 0, no operations needed
        if num == "0":
            return 0
        if len(num) == 1:
            return 1
        
        # Check for special cases
        last_zero = find_last('0')
        last_five = find_last('5')
        
        # If no 0 or 5, delete all digits except one
        if last_zero == -1 and last_five == -1:
            return n
        
        min_ops = n  # Initialize with maximum possible operations
        
        # Check for "00"
        if last_zero != -1:
            second_last_zero = find_last('0', last_zero - 1)
            if second_last_zero != -1:
                min_ops = min(min_ops, n - second_last_zero - 2)
            else:
                min_ops = min(min_ops, n - 1)  # Keep just one zero
        
        # Check for "25"
        if last_five != -1:
            last_two = find_last('2', last_five - 1)
            if last_two != -1:
                min_ops = min(min_ops, n - last_two - 2)
        
        # Check for "50"
        if last_zero != -1:
            last_five_before_zero = find_last('5', last_zero - 1)
            if last_five_before_zero != -1:
                min_ops = min(min_ops, n - last_five_before_zero - 2)
        
        # Check for "75"
        if last_five != -1:
            last_seven = find_last('7', last_five - 1)
            if last_seven != -1:
                min_ops = min(min_ops, n - last_seven - 2)
            else:
                min_ops = min(min_ops, n )  # Keep just one five
        
        return min_ops
16800