🚀Simplest Solution🚀3 Approaches||🔥Heap Sort | Merge Sort || Priority Queue ||🔥C++
Consider\uD83D\uDC4D\n\n                    Please Upvote If You Find It Helpful\n\n # Intuition \n Describe your first thoughts on how to solve this problem. \
# Consider\uD83D\uDC4D\n```\n                    Please Upvote If You Find It Helpful\n```\n<!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n<!-- # Approach -->\n<!-- Describe your approach to solving the problem. -->\n\n<!-- # Complexity\n- Time complexity: -->\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n<!-- - Space complexity: -->\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n**Heap Sort**\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n```\nclass Solution {\npublic:\n    void maxHeapify(vector<int>& nums, int n, int i){\n        int largest = i;\n        int left = (2 * i) + 1, right = (2 * i) + 2;\n        if(left < n && nums[left] > nums[largest])\n            largest = left;\n        if(right < n && nums[right] > nums[largest])\n            largest = right;\n        if(largest != i){\n            swap(nums[largest], nums[i]);\n            maxHeapify(nums, n, largest);\n        }\n    }\n\n    void heapSort(vector<int>& nums, int n){\n        for(int i = n/2-1; i >= 0; i--)\n            maxHeapify(nums, n, i);\n        for(int i = n-1; i >= 0; i--){\n            swap(nums[0], nums[i]);\n            maxHeapify(nums, i, 0);\n        }\n    }\n\n    vector<int> sortArray(vector<int>& nums) {\n        heapSort(nums, nums.size());\n        return nums;\n    }\n};\n```\n\n**Merge Sort**\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n```\nclass Solution {\npublic:\n    void merge(int low, int mid, int high, vector<int> &nums) {\n        if (low >= high) return;\n        int l = low, r = mid + 1, k = 0, size = high - low + 1;\n        vector<int> sorted(size, 0);\n        while (l <= mid and r <= high)\n            sorted[k++] = nums[l] < nums[r] ? nums[l++] : nums[r++];\n        while (l <= mid) \n            sorted[k++] = nums[l++];\n        while (r <= high) \n            sorted[k++] = nums[r++];\n        for (k = 0; k < size; k++)\n            nums[k + low] = sorted[k];\n    }\n\n    void mergeSort(vector<int>& nums, int start, int end){\n        if(start < end){\n            int mid = start + (end - start) / 2;\n            mergeSort(nums, start, mid);\n            mergeSort(nums, mid + 1, end);\n            merge(start, mid, end, nums);\n        }\n    }\n\n    vector<int> sortArray(vector<int>& nums) {\n        mergeSort(nums, 0, nums.size()-1);\n        return nums;\n    }\n};\n```\n**Priority Queue**\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n```\nclass Solution {\npublic:\n    vector<int> sortArray(vector<int>& nums) {\n        priority_queue<int, vector<int>, greater<int>> pq;\n        for(int i : nums)\n            pq.push(i);\n        for(int i=0;i<nums.size();i++){\n            nums[i] = pq.top();\n            pq.pop();\n        }\n        return nums;\n    }\n};\n```\n```\n                       `Give a \uD83D\uDC4D. It motivates me alot`\n```\nLet\'s Connect On [Linkedin](https://www.linkedin.com/in/naman-agarwal-0551aa1aa/)
['Divide and Conquer', 'C', 'Heap (Priority Queue)', 'Merge Sort', 'C++']