# Cannot pass one of the tests, but seems nothing wrong for the Custom Testcase

• My code cannot pass one of the tests after submission. However, when I type the same test case into the Custom Testcase field and run the code, it seems that my code generates the correct result.

Here is my code:

``````class Solution {
public:
unordered_map<string, int> m;

/* Calculate the 'distance' between two characters.
The 'periodic boundary condition' is also considered. E.g. 'a' - 'z' = 1. */
char distance(char a, char a0)
{
int dist = a - a0;
if(dist > 13) dist -= 26;
else if(dist <= -13) dist += 26;
return '0' + dist;
}

/* Shift the string then register the shifted string into an unordered_map.
The return value specifies when the key appears for the first time. */
int calcInd(string& s)
{
string k;
for(int i = 0; i < s.size(); i++)
k.push_back(distance(s[i], s[0]));

if(!m.count(k))
{
int temp = m.size();
m[k] = temp;
}
return m[k];
}

vector<vector<string>> groupStrings(vector<string>& strings) {
vector<int> index(strings.size());
int i;

for(i = 0; i < strings.size(); i++)
index[i] = calcInd(strings[i]);

vector<vector<string>> result(m.size());

for(i = 0; i < strings.size(); i++)
result[index[i]].push_back(strings[i]);

return result;
}
};
``````

The idea of my code is to use the function "calcInd" to shift each string and register the shifted string into an unordered_map. In the main function, the array 'index' stores the size of the map when the key corresponding to the current string first appears. Thus, if two strings are different after shifting, the 'index' of them should be different. We can then use this 'index' to specify the location of each group in the result vector.

The result of the test case mentioned above is as below.

Input:

My answer and the expected answer are the same except the order of these groups and the order of strings within the same group. Specifically, my answer is: