Need Help , O(n^2) Sol getting tle
I am checking for all the possible differences which may give answer in O(n) so expected time complexity should be O(n^2) but its getting tle , can someone poin
I am checking for all the possible differences which may give answer in O(n) so expected time complexity should be O(n^2) but its getting tle , can someone point out the mistake\n```\nclass Solution {\npublic:\n    vector<int> recoverArray(vector<int>& nums) {\n        set<int>diff;\n        int n = nums.size();\n        for(int i=1;i<n;i++){\n            diff.insert(abs(nums[i] - nums[0]));\n        }\n        vector<int>ans(n/2,0);\n        sort(nums.begin(),nums.end());\n        unordered_map<int,int>mp1;\n        for(auto x:diff){\n            if(x==0 || x&1){\n                continue;\n            }\n            mp1.clear();\n            int cnt = 0;\n            for(int i=0;i<n;i++){\n                mp1[nums[i]]++;\n            }\n            for(int i=0;i<n;i++){\n                if(mp1[nums[i]] && mp1[nums[i] + x]){\n                    mp1[nums[i]]--;\n                    mp1[nums[i] + x]--;\n                    cnt++;\n                }\n                else if(mp1[nums[i]]){\n                    break;\n                }\n            }\n            if(cnt==n/2){\n                for(int i=0;i<n;i++){\n                    mp1[nums[i]]++;\n                }\n                cnt =0;\n                for(int i=0;i<n;i++){\n                    if(mp1[nums[i]] && mp1[nums[i] + x]){\n                        mp1[nums[i]]--;\n                        mp1[nums[i] + x]--;\n                        ans[cnt] = nums[i] + x/2;\n                        cnt++;\n                    }\n                }           \n                return ans;\n            }\n        }\n        return ans;\n    }\n};\n```
[]