What is the space and time complexity of this program?

     unordered_map<int,vector<int>> lookup;
     int degree=0;
     for(int i=0;i<nums.size();i++)
     {
         lookup[nums[i]].push_back(i);
     }
     for(int i=0;i<nums.size();i++)
     {
         int n=lookup[nums[i]].size();
         degree=max(degree,n);
     }
     int ans=nums.size();
     for(auto i:lookup)
     {
         if(i.second.size()==degree)
             ans=min(ans,(i.second.back()-i.second.front()+1));
     }
    return ans;

hello @kani001

it is O(n).
becuase u are just storing n indices in lookup table.

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.