Please tell doubt in this one

Please tell doubt in this one.


Hey @cbcao263 what issue you are facing in this?

Bro I have mentioned in IDE.
And Explained too.
It is giving error on Leetcode

Hy @cbcao263, yaar tune yeh toh shi kiya ki sort krdiya pr 2 D vector lene ki koi jrort thodi hai ab, ab kya kr 2 pointer approach use kr. Start from 0th index and n-1th index of vector. Add both of them, if resultant is less more than the target value. Then decrement (n-1)th index and check for n-2. Whereas if 0th index and n-1th index of vector sum is less then the target value then increment you 0th index and check for 1st index

Han Bhai wo baat shi hain aapki
But Question mein ek problem hain

Like agar pehle mene sorting krdi na
Tn fir saare index change hojayenge

nd In Question, wo apne se maang rha hain original index as being pprovided in Original Array without sorting.
Isliye 2D Vector leliya
means vector of pair leliya ek mein number daaldiya nd ek mein index original array ka
fir sorting ki
nd fir check kiya
nd fir jahan match krenge

wahan jaake mein vector ke pair se indx uthake res vector mein store krduga

Ha ha ek dum sahi approach hai, issue kha aa rha h , dekh v[i].first or v[i].second honge woh dekhliyo or shayd vector v[i].first ke basis pr sort krta h toh first pr values store kriyo index ni

And use make pair function to store value

Han bro, whi kiya
Ussi ke base pe sort kiya
nd It’s running fine for first test case
2nd mein dikkat aarhi

[3,2,4]
6
isme

Maybe code mai issue hoga , ek brings check krlena pair 2,4 toh h


Try something like this, unordered leLe

Vector will also work,but keep proper implementation also

mtlb map se
han hojayega

but vector mei idk why kyu dikkat aarhi
because I think pair raise kaam nhi krta hoga
Aise 2dVector Matrix kaam krta hoga
vector<pair<int,int> > Thodi Implemenetation alag hogi iski I think

But agar mene map use kiya fir bhi problem hogi I think
Think of this test case
[3,3]
6
isme 2 keys hojayegi 3
Multimap shi rhega fir

Try unordered only, if it doesn’t work go for multimap, but I think it will accept solution using unordered map only.

Ohkayy bro
Hogya
vector se hi
actually v nd nums dono ko sort krna tha

nd bro One more doubt
Like I am doing Leetcode daily
So jaise aaj Sept Long Challenge ka Question tha
Jo DP ka tha
Like I am not comfortable in DP
ton krna shi rhega
ya chordu>

I am teaching students, still sometimes I am not able to think of an approach. But I can’t leave it right. So I’ll suggest you the same, give it a try, if you aren’t successful in solving it then you can find solutions on YouTube too. So I guess you got your answer :slight_smile:

1 Like

Sure bro, Thanks for the motivation.

Ek yeh kaise krna hoga


Hey @cbcao263 it would be great if you can ask this as a new doubt. It will soon hit its reply limit