You are viewing a single comment's thread. Return to all comments →
My code is not clearing many testcases can you tell me why?
int maxLen(string s){ char alpha[26][26]; int value[26][26]; for(int i = 0 ; i < 26; i++){ for(int j = 0 ; j < 26; j++){ value[i][j] = 0; } } for(int i = 0; i < s.length(); i++){ int index = s[i] - 'a'; for(int j = 0; j < 26; j++){ if(alpha[index][j] != s[i] && (value[index][j] != -1)){ alpha[index][j] = s[i]; value[index][j]++; } else{ value[index][j] = -1; } if(alpha[j ][index] != s[i] && value[i][index] != -1){ alpha[j][index] = s[i]; value[j][index]++; } else{ value[j][index] = -1; } } } int maxlen = value[0][0]; for(int i = 0 ; i < 26; i++){ for(int j = 0 ; j < 26; j++){ if(maxlen < value[i][j]) maxlen = value[i][j]; } } if(maxlen> 0){ return maxlen; } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Two Characters
You are viewing a single comment's thread. Return to all comments →
My code is not clearing many testcases can you tell me why?