Company: visa_6oct
Difficulty: medium
Alien Code Substrings Divisible by 3 Problem Description Suppose you are reviewing activity logs pulled from a piece of speculative alien hardware. You have a digit string alienCode representing recorded device activity codes. Count how many substrings of this string, when read as numbers, are exactly divisible by 3. A qualifying substring must not begin with a zero, unless the substring is simply the single character "0". Note: You are not expected to provide the most optimal solution, but an O(alienCode.length) solution is expected, using the fact that a number is divisible by 3 if and only if the sum of its digits is divisible by 3. A string of digits representing alien device activity codes. Input: string alienCode Output: integer (Return the number of substrings that form an integer divisible by 3.) Examples Example 1: Input: alienCode = "456" Output: 3 Explanation: Looking at every substring of the given string: alienCode[0..0] = 4 isn't divisible by 3. alienCode[1..1] = 5 isn't