Arrays-Target Sum Pair

For Solving This, My Approach Was Hashing Based & All Test Cases Failed. So I Unlocked Test Cases.
Than I Found that My Answer Was Matching but in Solution 2 Pointer Approach Was Used.
My Code is also Giving Exactly Same No of Pairs but not Necessarily in Same Order.

Suppose Target Sum = 5 and My Pairs are (2,3) (4,1) etc and Coding Blocks Test Cases Showed (3,2) (1,4) or (1,4) (3,2) Like This.
So, I Think My Answer Should be Accepted because Approach is Up to me & My Solution is also Running in O(n) Like 2 Pointer Does.

Hey @rtg67GHu_67
it’s okay if your pairs are not being printed in right order, the answer is still correct,
Though You may try using map instead of unordered map, then it’ll be in the right order, if still you are not able to get them in the right order, post your code.

But MAP takes O(nlogn) , that’s the problem.
So, Will I get marks for this question?

@rtg67GHu_67
Try that out

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.

You Didn’t get My Point, the Question Needed to Print Pairs, So I Did.

You Didn’t get My Point, the Question Needed to Print Pairs, So I Did. Why Should I Sort to Satisfy Test Cases? That’s My Question. (x,y) and (y,x) both are giving sum x+y, so it doesn’t matter I print (x,y) or (y,x). and also, in question there was no mention to print pairs in order.

@rtg67GHu_67 you are right, in some questions order does not matter but in some questions order matters. Think of it like an additional constraint and think how would you tackle this obstacle.
No, you will not get points for this problem if you have already unlocked test cases or solution.

1 Like

Okay, I got it.
There was a Hidden Constraint :joy:

1 Like

@rtg67GHu_67 in the future you can assume that order of the output matters. It is mostly mentioned if it doesn’t matter, but nothing is mentioned if it does!

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.