-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Description
LeetCode Username
https://leetcode.com/rajkmeena/
Problem number, title, and link
2982. Find Longest Special Substring That Occurs Thrice II
Category of the bug
- Missing test Case (Incorrect/Inefficient Code getting accepted because of missing test cases)
Description of the bug
The output should be wrong for the provided code, but the code get accepted
Language used for code
C++
Code used for Submit/Run operation
class Solution {
public:
int maximumLength(string s){
int n=size(s);
map<char,vector<int>>mp;
int cnt=1;
for(int i=1; i<n; i++){
if(s[i-1]==s[i]){
cnt++;
}
else{
mp[s[i-1]].push_back(cnt);
cnt=1;
}
}
mp[s[n-1]].push_back(cnt);
// for(auto x:mp){
// cout<<x.first<<endl;
// for(auto y:x.second){
// cout<<y<<" ";
// }
// cout<<endl;
// }
int ans=-1;
for(auto x:mp){
sort(x.second.begin(),x.second.end(),greater<int>());
if(x.second.size()>=3){
if(x.second[0]>2){
if(x.second[0]==x.second[1]){
ans=max(ans,x.second[0]-1);
}
else if(x.second[0]-x.second[1]>2){
ans=max(ans,x.second[0]-2);
}
else if(x.second[0]-x.second[2]<=2){
ans=max(ans,x.second[2]);
}
else{
ans=max(ans,x.second[1]);
}
}
else if(x.second[0]==2){
if(x.second[0]==x.second[2]){
ans=max(ans,2);
}
else{
ans=max(ans,1);
}
}
else{
ans=max(ans,1);
}
}
else if(x.second.size()==2){
if(x.second[0]>2){
if(x.second[0]==x.second[1]){
ans=max(ans,x.second[0]-1);
}
else if(x.second[0]-x.second[1]>2){
ans=max(ans,x.second[0]-2);
}
else{
ans=max(ans,x.second[1]);
}
}
else if(x.second[0]==2){
ans=max(ans,1);
}
}
else{
if(x.second[0]>=3) ans=max(ans,x.second[0]-2);
}
}
return ans;
}
};
Expected behavior
The output for the "eeeeeaeeeeebeeeee" should be 5 but the output of the code is 4. Still the code submitted.
