Same code is getting accepted in leetcode but incorrect here

All test cases are not getting paased thought sample input seems to be correct.

#include<bits/stdc++.h> using namespace std; vector<vector> groupAnagrams(vector& strs) { int n = strs.size(); vector<vector>ans; if( n == 0) return ans; unordered_map<string,vector>m; for(int i=0;i<n;i++) { string curr = strs[i]; sort(curr.begin(),curr.end()); m[curr].push_back(strs[i]); } for(auto p:m) { ans.push_back(p.second); } return ans; } int main() { int n; cin>>n; vectorv(n); for(auto &x:v) cin>>x; vector<vector>ans = groupAnagrams(v); /for(auto p:ans) { for(string s: p) { cout<<s<<" "; } cout<<endl; }/ for(int i=0;i<ans.size();i++) { for(int j=0;j<ans[i].size();j++) { cout<<ans[i][j]; if(j<ans[i].size()-1)cout<<" "; } cout<<endl; } }

Hey @updesh13 yes , your code won’t get accepted cause it’s mentioned in the question that output of the order won’t matter. But at the backend it’s only taking particular expected output. So if it’s getting accepted at leetcode then your code is logically correct.

Okay Thanks for confirmation.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.