Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6379
@blackshadows 6329
@mb1973 5358
@Quandray 5231
@akhayrutdinov 5111
@saiujwal13083 4510
@sanjay05 3762
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3357
@KshamaGupta 3318
Complete Leaderboard
Number of substrings divisible by 8 but not by 3
Easy Accuracy: 17.75% Submissions: 62 Points: 2

Given string s of digits “0-9”, the task is to find the number of substrings which are divisible by 8 but not by 3.

Example 1:

Input: s = "888"
Output: 5
Explanation: Substring indexes : 
(0, 0), (0, 1), (1, 1), (1, 2), (2, 2).
Example 2:
Input: s = "083"
Output: 2
Explanation: Substring indexes :
(1, 1), (0, 1)

Your Task:  
You don't need to read input or print anything. Complete the function countDivisibleSubstring() which takes s input parameter and returns the integer value

Expected Time Complexity: O(|s|)
Expected Auxiliary Space: O(|s|)

Constraints:
1 ≤ |s| ≤ 106

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Number of substrings divisible by 8 but not by 3

Output Window