Related to answers

3: How it O(n^2)?
7: Why shouldn’t we use a comparator according to the answer to the question?Will sort(data.begin,data.end) work for vector of pairs?
9: How will a graph be stored as a linear array?
10: How would the push function take O(1) time?

Hi @pradhumangupta99,

  1. i have explained in detail here : Explain the answer?
  2. i have explained here : How is the answer in this case is 2?
  3. if you are taking about this vector < int > graph [ N + 1 ] then its not a linear array its an array of vector which is multidimentional
  4. you can assign two pointers say i and j to denote first and last element in the stack when you push a new element,all you need to do is stack[j]= inserted element and j++, and when you pop then simply i++;

In case of any doubt feel free to ask :slight_smile:
mark your doubt as resolved if you got the answer

IN your explanation:

IN your explanation: 3:will it be true for arrays too? 4:vector will be of pairs or vector of vector? if pairs then in that case will it be true what you have explained? 9:so vector behaves like a datatype for graph[N+1]?

3.we pass arrays as pointers (not by values)so it won’t be true
4. i think u have resolved the answer due to which i am not able to see the question, so send me the question so that i can check.
9. yes , vector is a custom data type as any classes and structures are used for making data types

4th ques was:
Given an array of N integers.

We wish to sort these integers but we must remember what their orignal indices were before sorting.
my prev question was related to this-
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()).

yes ,this is actually the way u have to do( instead of data you can use pair ).

@pradhumangupta99 abhijeet have answered your queries. Do you have any doubts now?