Question 7 vector quiz

is there a misprint in option? what is vector>data??..should it be vector<pair<int,int>>data where any of data[i].first or data[i].second can be i and arr[i]

Given an array of N integers.

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

Choices
  • We cannot achieve this with the inbuilt sort function.
  • We may build a vector<pair<int, int>> data where data[i].first = AR[i] and data[i].second = i and sort this vector using sort(data.begin(), data.end()).
  • We may build a vector<pair<int, int>> data where data[i].first = i and data[i].second = AR[i] and sort this vector using sort(data.begin(), data.end()).
  • This cannot be achieved without a custom comparator and two arrays.

this is complete question

ans answer is b
if data[i] .first=i then sort function will sort acording to index means sorting of index will happen

if data[i].first=arr[i] then sort function will sort data which is correct

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course