Sort by

recency

|

3696 Discussions

|

  • + 0 comments

    Here is my Python solution!

    def repeatedString(s, n):
        return list(s).count("a") * (n // len(s)) + list(s)[:n % len(s)].count("a")
    
  • + 0 comments

    I absolutely love how the concept of "Repeated String" can be explored in so many creative ways! It reminds me of how important it is to go through a purity test when tackling patterns and structures. Speaking of which, Wisp Willow has this enchanting ability to tie things together with such grace—much like how repeating elements create something truly mesmerizing.

  • + 0 comments

    My C code 😁😎

    long repeatedString(const char* s,const long n) {
        if(strlen(s) == 1) {
            return (s[0] == 'a') ? n : 0;
        }
    
        long long isA = 0;
        long len = strlen(s);
        for(long i = 0;i < strlen(s);i++) {
            if(s[i] == 'a') {
                isA++;
            }
        }
    
        long long numberOfTimes = n / len;
        long long remaining = n % len;
        long long totalA = numberOfTimes * isA;
    
        for(long i = 0;i < remaining;i++) {
            if(s[i] == 'a') {
                totalA++;
            }
        }
        printf("number : %lld and isA = %ld\n",numberOfTimes,isA);
        return totalA;
    }
    
  • + 0 comments

    A one line implementation in Python 3:

    def repeatedString(s, n):
        return s.count("a")*(n//len(s)) + s[:n%len(s)].count("a")
    
  • + 0 comments

    C# simple solution:

    public static long repeatedString(string s, long n)
        {
            int countInSingleString = s.Count(c=>c == 'a');
            var quotient = n/s.Length;
            var remainder = n%s.Length;
            var aCnt = countInSingleString * quotient;
            if(remainder > 0)
                aCnt += s.Substring(0,(int)remainder).Count(c=>c =='a');
            return aCnt;
        }