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
Input
s = "12936"Output
11Substrings
"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
Input
s = "5701283"Output
18The 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.