Count Substrings Divisible By Last Digit

You are given a string s consisting of digits.

Return the number of substrings of s divisible by their non-zero last digit.

Note: A substring may contain leading zeros.

Example 1
Inputs = "12936"
Output11
Substrings "29", "129", "293", and "2936" are not divisible by their last digit, so out of 15 total substrings the answer is 15 - 4 = 11.
Example 2
Inputs = "5701283"
Output18
The listed 12 multi-digit substrings are divisible by their last digit, and the 6 single non-zero digit substrings are also divisible by themselves, giving 12 + 6 = 18.

Constraints

  • 1 <= s.length <= 10^5
  • s consists of digits only.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate