[Codeforces-888C] - K-Dominant Character

C. K-Dominant Character
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.

You have to find minimum k such that there exists at least one k-dominant character.

Input

The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).

Output

Print one number — the minimum value of k such that there exists at least one k-dominant character.

Examples
input
Copy
abacaba
output
Copy
2
input
Copy
zzzzz
output
Copy
1
input
Copy
abcde
output
Copy
3
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    string str;
    while(cin>>str){
        getchar();
//        cout<<" len = "<<str.length()<<endl;
        int ans = 1e6;
        for(int i='a';i<='z';i++){
            int k = 0, t = 1;
            for(int j=0;j<str.length();j++){
                    
                if(str[j]==i)
                    t=1;
                else 
                    t++;
                k = max(k,t);
            }
//            cout<<" k = "<<k<<endl; 
            ans = min(k,ans);
        }
        cout<<ans<<endl;
    }
}

 

posted @ 2019-03-09 17:24  峰寒  阅读(268)  评论(0编辑  收藏  举报