How to perform operations

How do I swap the values in the hashmap
and how can I print the hash map?

Hi @goyalvivek
what do u mean by swapping values in hashmap…
regarding printing the hashmap, lets considers a map<int,int> mp
u can print it like this

for(auto x:mp){
cout<<x.first<<" "<<x.second<<endl;
}

yes, i know this type or printing, in the question, i have to print the max possible permutation

what do u mean by max possible permutation?? pls share the ques u are referring to

Shekhar is a bomb defusal specialist. He once encountered a bomb that can be defused only by a secret code. He is given a number N and a number K. And he is also given permutation of first N natural numbers . The defusal code is the largest permutation possible by doing atmost K swaps among a pair of the given permutation. Help him to find the final permutation.

are bhai ques link ya pure ques ki pic bhejo na… or ask doubt under that particular ques only… u have asked in ques unlock

can i get the key with the help of value?

map stores key value pair… u can get value from key… not key from value… for that u will have to do normal traversal only and check…

yes, sir, it is the same question

okay… u can refer this code https://ide.codingblocks.com/s/640120
try to dry run it on sample test case… ur doubt will be cleared…

in the helping vide, the solution shows that we should store the data on hash map and swap accordingly, my question is, I can swap the indexes using their keys, but how am i supposed to print it?

refer the code i sent u

please help find the error https://ide.codingblocks.com/s/640140

what is the error???

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.