Sort by

recency

|

3683 Discussions

|

  • + 0 comments

    JavaScript Solution

    /*
     * Complete the 'repeatedString' function below.
     *
     * The function is expected to return a LONG_INTEGER.
     * The function accepts following parameters:
     *  1. STRING s
     *  2. LONG_INTEGER n
     */
    
    function repeatedString(s, n) {
        let countInOriginal = 0; 
        
        for(let c of s) {
            countInOriginal += c === 'a' ? 1 : 0;
        } 
        
        
        let fullRepeats = Math.floor(n / s.length); 
        let count = fullRepeats * countInOriginal; 
        
        let remaining = n % s.length; 
        
        for(let i = 0; i < remaining; i++) {
            count += s[i] === 'a' ? 1 : 0; 
        } 
        
        return count; 
    }
    
  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/Vh5davsSkfA

    long ccount(string s) {
        return count(s.begin(), s.end(), 'a');
    }
    
    long repeatedString(string s, long n) {
        return (n / s.size()) * ccount(s) + ccount(s.substr(0, n % s.size()));
    }
    
  • + 0 comments

    JavaScript Solution

    let length =s.length,count=1,repeactChar='a'; let repetWord = Math.floor(n/length); let remainderChar = n%length;; for(let i = 0; i < length; i++){ if(repeactChar == s[i]) count++; } count = count * repeatWord; for(let j = 0; j < remainderChar; j++){ if(repeactChar ==s[j]) count++; } return count

  • + 0 comments

    I have submitted my code in Python 3. But i am seeing runtime error for few of the testcases. Please suggest what need to change.

    !/bin/python3

    import math import os import random import re import sys

    def repeatedString(s, n): # Write your code here if s == 'a': return n elif (1 <= len(s) <= 100) and (1 <= n <=1000000000000): i = int(n / len(s)) st = s * i i = int(n % len(s)) st = st + s[0:i] return (st.count('a')) else: return 0 if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w') s = input() n = int(input().strip()) result = repeatedString(s, n) fptr.write(str(result) + '\n') fptr.close()

  • + 0 comments

    Repeated String is such an interesting concept! It reminds me of how important sound quality is in our everyday lives. Speaking of which, have you ever tried using sound deadening composites? They really make a difference in reducing noise levels and creating a more peaceful environment. It's amazing how a little change can enhance our experience!