unordered_map<int,vector> lookup;
What is the space complexity of this map if for every number i(i<=n) we insert some m numbers into the vector.
Space Complexity
Hello @kani001do you know about the unordered map and map that will be according to that.
Please confirm this.
yes…but only time complexity will change for map and unorderedmap right…but my doubt is about space complexity?
// unordered_map<int,vector> 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;
what will be the time and space for this program?
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.