
China test
Prompt
Write a python function to count the number of substrings with the sum of digits equal to their length. Your function should satisfy these tests: ```python assert count_Substrings('112112') == 6 assert count_Substrings('111') == 6 assert count_Substrings('1101112') == 12 ```
Answer guidance
Reference solution: from collections import defaultdict def count_Substrings(s): n = len(s) count,sum = 0,0 mp = defaultdict(lambda : 0) mp[0] += 1 for i in range(n): sum += ord(s[i]) - ord('0') count += mp[sum - (i + 1)] mp[sum - (i + 1)] += 1 return count
Drag to resize
Drag to resize
Drag to resize
Drag to resize
Response not available
Drag to resize