Mike and hasing

it gives tle for 2 cases and passes other cases.

Hey @div_yanshu07 it’s because of the for loop in line 26 logic, your code is correct just increasing time complexity cause of this for loop. Take reference from this code, I have implemented it using vector https://ide.codingblocks.com/s/345895

There’ s some issue with this code. It gives compilation error.

It must be giving TLE not complication error, Use unordered map instead of map. It might help.

Then, what’s this error?
source.cpp:8:12: warning: null character(s) ignored
8 | unordered_b map<int, int>last; //stores the last position of every integer that occurred in the array.
| ^
source.cpp:10:2: warning: null character(s) ignored
10 | b bool compare(int a,int b) //sorting by last position
| ^
source.cpp:14:2: warning: null character(s) ignored
14 | b int main()
| ^
source.cpp:8:1: error: ‘unordered_b’ does not name a type
8 | unordered_b map<int, int>last; //stores the last position of every integer that occurred in the array.
| ^~~~~~~~~~~
source.cpp:10:1: error: ‘b’ does not name a type
10 | b bool compare(int a,int b) //sorting by last position
| ^
source.cpp:14:1: error: ‘b’ does not name a type
14 | b int main()
| ^

Make it unordered_map

I have taken care of that but it still throws same error. You can compile at your end.

Give me sometime. Cb ide is not working. I’ll send you proper code asap, till then you can do your next question. I’ll let you know, when it will be done :slight_smile:

Hey @div_yanshu07 is this code still not working ?

It works now but gives tle for one case

After using unordered_map?

It works now! Thankyou

Your welcome @div_yanshu07

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.