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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Repeated String

Repeated String

Problem
Submissions
Leaderboard
Discussions
Editorial

There is a string, , of lowercase English letters that is repeated infinitely many times. Given an integer, , find and print the number of letter a's in the first letters of the infinite string.

Example

The substring we consider is , the first characters of the infinite string. There are occurrences of a in the substring.

Function Description

Complete the repeatedString function in the editor below.

repeatedString has the following parameter(s):

  • s: a string to repeat
  • n: the number of characters to consider

Returns

  • int: the frequency of a in the substring

Input Format

The first line contains a single string, .
The second line contains an integer, .

Constraints

  • For of the test cases, .

Sample Input

Sample Input 0

aba
10

Sample Output 0

7

Explanation 0
The first letters of the infinite string are abaabaabaa. Because there are a's, we return .

Sample Input 1

a
1000000000000

Sample Output 1

1000000000000

Explanation 1
Because all of the first letters of the infinite string are a, we return .

Author

tunyash

Difficulty

Easy

Max Score

20

Submitted By

540057

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy