We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Repeated String
Repeated String
Sort by
recency
|
3683 Discussions
|
Please Login in order to post a comment
JavaScript Solution
Here is my c++ solution, you can watch the explanation here : https://youtu.be/Vh5davsSkfA
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
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()
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!