- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions

# Program to find maximum k-repeating substring from sequence in Python

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

## Example (Python)

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))

## Input

"papaya", "pa"

## Output

2

- Related Articles
- Program to find length of longest repeating substring in a string in Python
- 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++
- Program to find maximum time to finish K tasks in Python
- Longest Substring Without Repeating Characters in Python
- Program to find removed term from arithmetic sequence in Python
- Find maximum length Snake sequence in Python
- 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 number of ways we can select sequence from Ajob Sequence in Python
- Program to find maximum length of k ribbons of same length in Python
- Longest Repeating Substring in C++
- Program to find length of longest substring with character count of at least k in Python