Strings-max frequency character

problem statement :- Take as input S, a string. Write a function that returns the character with maximum frequency. Print the value returned.

my code is -
#include
#include
using namespace std;

int main() {
char str[1000];
cin>>str;

int freq[26] = {0};
int FREQ[26] = {0};

for(int i=0;i<strlen(str);i++){
if(str[i]<=122&&str[i]>=97)
freq[str[i]-‘a’]++;

else
  FREQ[str[i]-'A']++;

}

int max=0;
for(int i=0;i<26;i++){
if(max<freq[i]){
max = i;
}
}
int flag=-1;
for(int i=0;i<26;i++){
if(max<FREQ[i]){
max = i;
flag=1;
}
}
if(flag==-1){
cout<<(char)(max+97);
}
else if(flag==1){
cout<<(char)(max+65);
}
return 0;
}

i am getting wrong answer in 2 testcases please help?

There are a total of 256 characters. So you can make an array of that size and increase frequency corresponding to the ascii code. Then calculate maximum frequency at the end from that array