#include<bits/stdc++.h>
using namespace std;
bool f(int k,string& s){
for(int i=0;i<=25;i++){
vector<int> freq(26,0);
bool f=true;
for(int j=0;j<k;j++){
freq[s[j]-'a']++;
}
if(freq[i]==0) f=false;
int start=0;
int end=k-1;
while(end<=s.size()-1){
freq[s[start]-'a']--;
start++;
end++;
if(end<s.size()){
freq[s[end]-'a']++;
if(freq[i]==0) f=false;
}
}
if(f) return true;
}
return false;
}
int main(){
string s="";
cin>>s;
int low=0;
int high=s.size();
int ans=-1;
while(low<=high){
int mid=(low+high)/2;
if(f(mid,s)) high=mid-1,ans=mid;
else low=mid+1;
}
cout<<ans<<endl;
}
153. Find Minimum in Rotated Sorted Array | 150. Evaluate Reverse Polish Notation |
144. Binary Tree Preorder Traversal | 137. Single Number II |
130. Surrounded Regions | 129. Sum Root to Leaf Numbers |
120. Triangle | 102. Binary Tree Level Order Traversal |
96. Unique Binary Search Trees | 75. Sort Colors |
74. Search a 2D Matrix | 71. Simplify Path |
62. Unique Paths | 50. Pow(x, n) |
43. Multiply Strings | 34. Find First and Last Position of Element in Sorted Array |
33. Search in Rotated Sorted Array | 17. Letter Combinations of a Phone Number |
5. Longest Palindromic Substring | 3. Longest Substring Without Repeating Characters |
1312. Minimum Insertion Steps to Make a String Palindrome | 1092. Shortest Common Supersequence |
1044. Longest Duplicate Substring | 1032. Stream of Characters |
987. Vertical Order Traversal of a Binary Tree | 952. Largest Component Size by Common Factor |
212. Word Search II | 174. Dungeon Game |
127. Word Ladder | 123. Best Time to Buy and Sell Stock III |