Some hint for the question


#1

Using sorting will increase T.C., Try to do something with bits


#2

We can’t use sorting because the given vector is constant, if we want to sort then we have to compromise on memory.


#3

Try Quick Sort for sorting. Or you can use inbuilt methods for sorting. Most of the languages use Quick Sort as inbuilt sorting algorithm.


#4

It can be done in O(n). Do something will & or ^ bitwise operator.