How it will gonna take O(1) time? If there are n elements in v1 and m elements in v2 and we need to swap them so I think that will not gonna work for O(1) as we can see here each element needs to be swapped with the v1 so we have to iterate over the whole array of v2.
I think O(m) is there .
How it will gonna take O(1) time?
Hi @aryan, there is a major difference between swap() in stl and vector::swap() .
swap() take O(M) time as it swaps each element one by one but vector::swap() take O(1) time as it swaps the address instead of elements which is a constant time operation.
u can learn more here :-
In case of any doubt feel free to ask
mark your doubt as resolved if you got the answer
Ohkkk Thanks Sir.
Sir One more help needed.
Can you please tell me How to get maximum out of this course?
And One More Like after some days I forgot the same question and algorithm. Please help me.
hi @cbcao263, practice as much as you can , I also forget some algo’s its completely normal and happens with everyone . one advise i can give you is to practice regularly , even if it is for one or two hours ,don’t skip any day you will definetly see the results
Thanks a lot Sir for the help.
…
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.