Minimum Operations to Make a Special Number - Problem
You are given a 0-indexed string num representing a non-negative integer.
In one operation, you can pick any digit of num and delete it. Note that if you delete all the digits of num, num becomes 0.
Return the minimum number of operations required to make num special.
An integer x is considered special if it is divisible by 25.
Input & Output
Example 1 — Basic Pattern
$
Input:
num = "2245047"
›
Output:
2
💡 Note:
We can form "2250" by deleting the digits '4' and '7'. Since 2250 % 25 = 0, we need 2 operations.
Example 2 — Single Zero
$
Input:
num = "2908305"
›
Output:
3
💡 Note:
We can form "2900" by deleting '8', '3', '5'. Since 2900 % 25 = 0, we need 3 operations.
Example 3 — Already Special
$
Input:
num = "10"
›
Output:
1
💡 Note:
10 is not divisible by 25. We delete '1' to get '0', and 0 % 25 = 0, so we need 1 operation.
Constraints
- 1 ≤ num.length ≤ 105
- num consists of only digits
- num does not contain any leading zeros
Visualization
Tap to expand
Understanding the Visualization
1
Input
String num representing a non-negative integer
2
Process
Find pattern ending (00, 25, 50, 75) with minimum deletions
3
Output
Minimum operations needed
Key Takeaway
🎯 Key Insight: Numbers divisible by 25 must end in 00, 25, 50, or 75 - find these patterns greedily
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code