본문 바로가기

알고리즘/해커랭크

Repeated String

문제

https://www.hackerrank.com/challenges/repeated-string/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=warmup

 

n번째까지 문자열 s를 반복했을 때 a의 개수 출력

 

 

 

제출한 코드

def repeatedString(s, n):
    x = n//len(s) # 개의 s + @
    dcnt = Counter(s)
    reminder = n%len(s)
    remcnt = Counter(s[:reminder])
    if reminder == 0:
        return dcnt['a']*x
    else:
        return dcnt['a']*x+remcnt['a']

 

 

'알고리즘 > 해커랭크' 카테고리의 다른 글

Arrays: Left Rotation  (0) 2020.03.16
Cats and a Mouse  (0) 2020.03.16
Counting Valleys  (0) 2020.03.09
Drawing Book  (0) 2020.03.09
Sock Merchant  (0) 2020.03.08