In my code at line it is showing index -97 outofbound. Why it is showing that? Where is the problem with my code?
I don't understand why it is showing. What is wrong with my code or my logic?
class Solution {
public:
vector<string> removeAnagrams(vector<string>& words) {
bool ans = true;
for(int i=1;i<words.size();i++){
int temp[26]={0};
for(int j=0;j<words[i].size();j++){
int x = words[i][j];
int y = words[i-1][j];
int check=x-97;
int check1 = y-97;
temp[check]++; // at this place it is showing error
temp[check1]--; // at this place it is showing error
}
for(int k=0;k<26;k++){
if(temp[k]) ans =false;
}
if(ans==true){
words.erase(words.begin()+i);
i--;
}
}
return words;;
}
};