Java - find and check k fits or not || PriorityQueue
\nclass Solution {\n    public int[] recoverArray(int[] nums) {\n        \n    \tint i,n=nums.length;\n    \tint ans[]=new int[n/2];\n    \tArrays.sort(nums);\n
````\nclass Solution {\n    public int[] recoverArray(int[] nums) {\n        \n    \tint i,n=nums.length;\n    \tint ans[]=new int[n/2];\n    \tArrays.sort(nums);\n    \tPriorityQueue<Integer> pq=new PriorityQueue<>();\n    \tfor(i=0;i<n;i++)\n    \t\tpq.add(nums[i]);\n    \tfor(i=1;i<n;i++)\n    \t{\n    \t\tPriorityQueue<Integer> pq1=new PriorityQueue<>(pq);\n    \t\tint p=0;\n    \t\tif((nums[0]+nums[i])%2==0)\n    \t\t{\n    \t\t\tint k=(nums[0]+nums[i])/2-nums[0];\n    \t\t\tif(k==0)\n    \t\t\t\tcontinue;\n    \t\t\tint curr=pq1.poll();\n    \t\t\twhile(pq1.contains((curr+k+k))) {\n    \t\t\t\n    \t\t\t\tpq1.remove(curr+k+k); \n\t\t\t\t\tans[p++]=curr+k;\n\t\t\t\t\tif(p==n/2)\n\t\t\t\t\t\tbreak;\n    \t\t\t\tcurr=pq1.poll();\n    \t\t\t}\n    \t\t\tif(p==n/2)\n    \t\t\t\tbreak;\n    \t\t}\n    \t}\n    \treturn ans;\n    }\n}\n````\n\nIf you guys get it then please upvote it:))
['Heap (Priority Queue)', 'Java']