Answer could be 2nd and 3rd option both right...its the same?

Given an array of N integers.

We wish to sort these integers but we must remember what their orignal indices were before sorting.

(1) We cannot achieve this with the inbuilt sort function.

(2) We may build a vector> data where data[i].first = AR[i] and data[i].second = i and sort this vector using sort(data.begin(), data.end()).

(3) We may build a vector> data where data[i].first = i and data[i].second = AR[i] and sort this vector using sort(data.begin(), data.end()).

(4) This cannot be achieved without a custom comparator and two arrays.

@pranavsaihgal911, note in option (2) we have data[i].first as AR[i] and in (3) we have data[i].first=i. if we don;t provide any comparator to the sort function then it will compare w.r.t the first element of the vector by default . so to remember its previous indexes we made array of vector of size 2 where the first value corresponds to value and second index corresponds to its index in the original value and finally we sorted the array using stl function which is option (2)

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.