Ctrl K

Erase Digits Until It Divides by 25

Medium
The string digits is the decimal form of a non-negative number (it may start with zeros). One operation erases any single digit; the remaining digits keep their order. If every digit is erased, the number counts as 0. Return the fewest erasures after which the number is divisible by 25.
Example 1
digits="93752" → 1

Erase the final 2: 9375 = 25 · 375.

Example 2
digits="806" → 2

Neither 80, 86 nor 806 is divisible by 25. Erase 8 and 6 to leave 0.

Example 3
digits="4" → 1

Erase the only digit, and the number becomes zero.

Constraints
  • 1 ≤ len(digits) ≤ 100
  • digits contains only the characters 0–9
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsRound Prices to a Total MediumCross Swaps of x and y MediumLucky Ticket With Blanks MediumSandwiched Chip Duel MediumTerms Sharing a Last Digit Medium
loading Python…
Input
digits="93752"
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 191 tests on the server, hidden ones included.