- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have a sequence of characters called s, we say a string w is k-repeating string if w is concatenated k times is a substring of sequence. The w's maximum k-repeating value will be the highest value k where w is k-repeating in sequence. And if w is not a substring of the given sequence, w's maximum k-repeating value is 0. So if we have s and w we have to find the maximum k-repeating value of w in sequence.

So, if the input is like s = "papaya" w = "pa", then the output will be 2 as w = "pa" is present twice in "papaya".

To solve this, we will follow these steps −

Count:= number of w present in s

if Count is same as 0, then

return 0

for i in range Count to 0, decrease by 1, do

if i repetition of w is present in s, then

return i

Let us see the following implementation to get better understanding −

def solve(s, w): Count=s.count(w) if Count==0: return 0 for i in range(Count,0,-1): if w*i in s: return i s = "papaya" w = "pa" print(solve(s, w))

"papaya", "pa"

2

- Related Questions & Answers
- Program to find kth lexicographic sequence from 1 to n of size k Python
- Program to find maximum sum by removing K numbers from ends in python
- Longest Substring with At Least K Repeating Characters in C++
- Find maximum length Snake sequence in Python
- Longest Substring Without Repeating Characters in Python
- Program to find removed term from arithmetic sequence in Python
- Program to find maximum time to finish K tasks in Python
- Longest Repeating Substring in C++
- Program to find length of longest substring which contains k distinct characters in Python
- Program to find maximum sum of popped k elements from a list of stacks in Python
- Program to find minimum possible maximum value after k operations in python
- Program to find longest awesome substring in Python
- Program to find maximum score from removing stones in Python
- Program to find maximum length of k ribbons of same length in Python
- Find maximum length Snake sequence in C++

Advertisements