title: Time Complexity of accessing element from vector vs unordered_map
body: <p>I was solving a quetion on InterviewBit <a href="https://www.interviewbit.com/old/problems/largest-permutation/" rel="nofollow noreferrer">https://www.interviewbit.com/old/problems/largest-permutation/</a>
  When I solved this question using unordered_map to store the indices of elements in teh array it showed Time Limit Exceeded but using a vectr for the same thing somehow improved the time complexicity...!!
  But accessing an element is also O(1) in unorderd_map
  I added my code also incase there was a problem with my code to be corrected.</p>
  <pre class="lang-cpp prettyprint-override"><code>vector&lt;int&gt; Solution::solve(vector&lt;int&gt; &amp;A, int B) {
      int n=A.size();
      int cnt=0;
      for(int i=1;i&lt;n;i++){
          if(A[i-1]&gt;A[i])
              cnt++;
      }
      if(cnt==n-1)
          return A;
      
      vector&lt;int&gt;mp(n+1,-1);
      for(int i=0;i&lt;n;i++){
          mp[A[i]]=i;
      }
      int i=0;
      int temp=n;
      while(i&lt;n &amp;&amp; temp&gt;=1 &amp;&amp; B!=0){
          if(A[i]!=temp){
          // {   cout&lt;&lt;A[i]&lt;&lt;&quot; &quot;&lt;&lt;temp&lt;&lt;endl;
              int x=A[i];
              A[i]=temp;
              A[mp[temp]]=x;
              mp[x]=mp[temp];
              mp[temp]=i;
              B=B-1;
          }
          i=i+1;
          temp=temp-1;
          
      }
      return A;
  }
  </code></pre>
  <p>P.S. I also think the problem is with adding an element to a unordered_map vs a vector but i'm not quiet sure</p>