Update appNew update is available. Click here to update.

Divisible Substrings

profile
Contributed by
Ratnesh
Easy
yellow-spark
0/40
15 mins
75 %
3 upvotes
Hashedin By Deloitte

Problem Statement

You are given a number in the form of a string β€˜S’ of length β€˜N’ consisting of characters from '0' to '9' (both inclusive) .

You must return the number of substrings that are divisible by 5. Some strings divisible by 5 are β€˜5’, β€˜370’, and β€˜1000’.

Note :

A substring can start with a zero. The given number may also contain leading zeroes.

Example:

β€˜S'= β€˜5203’

Here, four substrings are divisible by 5: β€˜5’, ’520’, β€˜20’, β€˜0’.
Hence the answer is 4.
Detailed explanation ( Input/output format, Notes, Images )
Constraints :
1 <= 'T' <= 10
1 <= 'N' <= 10^5
'0' <= 'S[i]' <= '9'


Time Limit: 1 sec
Sample Input 1 :
2
5
35602
3
100
Sample Output 1 :
6
5
Explanation Of Sample Input 1 :
For test case 1:

β€˜S'= β€˜35602’
Here, six substrings are divisible by 5: β€˜35’, ’3560’, β€˜5’, β€˜560’, β€˜60’, β€˜0’.
Hence the answer is 6.


For test case 2:

β€˜S'= β€˜100’
Here, five substrings are divisible by 5: β€˜10’, ’100’, β€˜0’, β€˜00’, β€˜0’.
Hence the answer is 5.
Sample Input 2 :
2
1
9
4
1555 
Sample Output 2 :
0
9
Full screen
Reset Code
Full screen
Autocomplete
copy-code
Console