Here is my code for this problem, which gives correct output on console, but shows trimmed result in returned output

```
class Solution {
public:
string convert(string s, int numRows) {
if(numRows <= 1) return s;
string ans = "";
numRows--;
for(int i = 0; i <= numRows; i++){
for(int j = 0; j < s.length();){
ans += s[i+j];
if(i != 0 && i != numRows && 2*numRows - i + j < s.length()){
ans += s[2*numRows - i + j];
}
j += (2*numRows);
}
}
cout << ans << endl;
return ans;
}
};
```

Test case :

"ABCDE"

3