---
# System prepended metadata

title: 2844. Minimum Operations to Make a Special Number
tags: [Leetcode, math, Medium, Greedy]

---

Link: https://leetcode.com/problems/minimum-operations-to-make-a-special-number/
## 思路
multiples of 25 only have "25", "50", "75", "00" as their end
so we need to find the minimum operations to make ```num``` end with those numbers
and get the minimum of them
if there is no way we can make ```num``` end with those four numbers, we need to check whether ```num``` includes a zero, if not, then we return ```len(num)```, ```len(num)-1``` otherwise
## Code
```python=
class Solution:
    def minimumOperations(self, num: str) -> int:
        targets = ["25", "50", "75", "00"]
        ans = inf
        for t in targets:
            last, secondLast = -1, -1
            for i in range(len(num)-1, -1, -1):
                if last == -1:
                    if num[i]==t[-1]:
                        last = i
                else:
                    if num[i]==t[0]:
                        secondLast = i
                        break
            if last!=-1 and secondLast!=-1:
                ans = min(ans, len(num)-1-last + last-secondLast-1)
        if ans != inf:
            return ans
        return len(num)-1 if '0' in num else len(num)
            
```
