Super Six Substrings

Sort by

recency

|

45 Discussions

|

  • + 0 comments

    Why not find the mod directly with 6, as opposed to 2 and 3 ?

  • + 0 comments

    According to the constraints , the string length will not exceed 10e5. Here is the input for test case 5: 6966606919907090609037430091834960718075082030963209339303030899600689446690866466014339933090600886

    wtf!!

  • + 0 comments

    include

    include

    char s[100005]; int arr[100005][3];

    int fun(int x,int m){

    if(x>=strlen(s))
    return 0;
    else if(arr[x][m]!=-1)
    return arr[x][m];
    else {
         if((s[x]-'0'+m)%3==0 && (s[x]-'0')%2==0){
        arr[x][m]=fun(x+1,(s[x]-'0'+m)%3)+1;
    }
        else {
        arr[x][m]=fun(x+1,(s[x]-'0'+m)%3); }
        return arr[x][m];
    }
    

    }

    int main(){ scanf(" %s",s); int j,i=0; long long ans=0; for(j=0;j<100005;j++){ arr[j][0]=arr[j][1]=arr[j][2]=-1;} while(s[i]!='\0'){ if((int)s[i]=='0'){

      ans=ans+1;
      }
    else {
        ans=ans+fun(i,0);
    
        }
    
            i++;}
        printf("%lld",ans);
    
    return 0;}
    //can anyone please help out.
    //my above code is giving time out for test cases above 12
    
  • + 0 comments

    https://www.hackerrank.com/contests/hourrank-18/challenges/super-six-substrings/submissions/code/1301177045

    O(n) solution in python.. and I know nothing of dynamic programming

  • + 0 comments

    can anyone explain whats wrong with my code? public class superString {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j <= s.length(); j++) {
                try {
                    // System.out.println(s.substring(i,j));
                    int k = Integer.valueOf(s.substring(i, j));
                    if (k==0) {
                        count++;
                    } else if ((s.substring(i, j).startsWith("0"))) {
                        count += 0;
                    } else {
    
                        if (k % 6 == 0) {
                            count += 1;
                        }
    
    
                    }
                }
    
                catch (Exception e) {
    
                }
            }
    
        }
        System.out.println(count);
    
    }
    

    }