Arrays-Target Sum Triplets-doubt

dear sir/mam i am using unordered_set to reduce the time complexity but to print it in the sorted manner what should i do …link:

dear sir/mam i am using unordered_set to reduce the time complexity but to print it in the sorted manner what should i do …link: https://ideone.com/axrB31

Hi Arghya, what you can do here is
In Line 24: store all the answers in a stack for each arr[i] instead of printing them
and then as soon as the loop is about to close i.e.
In Line 27: print all the elements in stack until it get’s empty.

For example:
U make a stack of vector as:

//Do this between line no. 17 & 18
vector< int > v(3) ;
stack < vector > s;

Now,

//Immediately after Line 24
v[0] = arr[i]
v[1] = sum-arr[j]
v[2] = arr[j]
s.push(v) ;

Now,

// Immediately After line 27
Take the top element of stack s(let’s say tp) and cout as:
cout << tp[0]<<","<<" “<<tp[1]<<” “<<“and”<<” "<<tp[2]<<endl

Since, using this approach is increasing your complexity it is recommended to try this question with a better approach and with an efficient code.
Hope this helps, Thank You :smile:

I am marking your doubt as Resolved for now. Re-open it if required