question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
maximum-elegance-of-a-k-length-subsequence | C++ Greedy in O(NlogN) | c-greedy-in-onlogn-by-yashsinghania-8l4q | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nTaking k elements and trying to maximise the answer by increasing unique | yashsinghania | NORMAL | 2023-08-06T11:26:09.200193+00:00 | 2023-08-06T11:26:09.200217+00:00 | 281 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTaking k elements and trying to maximise the answer by increasing unique elements\n\n# Complexity\n- Time complexity:\n- O(NlogN + N) for sorting and searching\n\n- Space complexity:\n- O(N)\n\n# Code\n```\nclass Solution {\... | 4 | 0 | ['C++'] | 4 |
maximum-elegance-of-a-k-length-subsequence | Greedy | greedy-by-jeffreyhu8-qhet | Intuition\nAs is often typical with subsequence problems, we may first think of a dynammic programming approach. However, having the state be something like the | jeffreyhu8 | NORMAL | 2023-08-06T04:01:54.390162+00:00 | 2023-08-06T04:05:23.014920+00:00 | 334 | false | # Intuition\nAs is often typical with subsequence problems, we may first think of a dynammic programming approach. However, having the state be something like the current item and the number of distinct values accumulated so far is too large.\n\nWhen there are strict bounds for a dynamic programming approach, a common ... | 4 | 0 | ['Greedy', 'Heap (Priority Queue)', 'Python3'] | 1 |
maximum-elegance-of-a-k-length-subsequence | ✅ Beat 100% | ✨ O(N + k log k) | 🏆 Most Efficient Solution | 💯 Simple Greedy | beat-100-on-k-log-k-most-efficient-solut-ysmx | Intuition\n Describe your first thoughts on how to solve this problem. \n * For each category, we would always pick the items with the largest profits.\n * If | hero080 | NORMAL | 2023-09-04T02:27:42.391526+00:00 | 2023-09-04T02:27:42.391555+00:00 | 122 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n * For each category, we would always pick the items with the largest profits.\n * If we picked any item in a category, we say we "picked this category".\n * The `max_profit` for each category is a key. Assume we sorted categories by t... | 3 | 0 | ['Greedy', 'Quickselect', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Video Solution | Complete Contest | C++ | Java | video-solution-complete-contest-c-java-b-7y39 | Intuition, approach, and time complexity discussed in detail in video solution\nhttps://youtu.be/uvF7-rRddzM\n\n# Code\nC++\n\nclass Solution {\npublic:\n lo | Fly_ing__Rhi_no | NORMAL | 2023-08-06T16:07:38.609958+00:00 | 2023-08-06T16:07:38.609981+00:00 | 240 | false | # Intuition, approach, and time complexity discussed in detail in video solution\nhttps://youtu.be/uvF7-rRddzM\n\n# Code\nC++\n```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(items.begin(), items.end(), [](const vector<int>&a, const vector<int> & b)->... | 3 | 0 | ['C++'] | 1 |
maximum-elegance-of-a-k-length-subsequence | [C++/Python] Easy Greedy Solution | beats 100 percent | cpython-easy-greedy-solution-beats-100-p-w2hm | Intuition\n Describe your first thoughts on how to solve this problem. \nTry to optimise between these two\n- Use items with maximum profits\n- Use items of max | UltraSonic | NORMAL | 2023-08-06T05:12:36.624197+00:00 | 2023-08-06T10:30:53.654445+00:00 | 295 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTry to optimise between these two\n- Use items with maximum profits\n- Use items of maximum distinct categories\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nStarted with adding all the items with maximum profits... | 3 | 0 | ['Greedy', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 1 |
maximum-elegance-of-a-k-length-subsequence | O(n) single pass for adding items and a single pass for removing items | on-single-pass-for-adding-items-and-a-si-9d25 | \nYou first greedily take all top profit values and get the minimal reasonable numCathegories. Then you increase the number of cathegories while removing the wo | Balwierz | NORMAL | 2023-08-17T17:22:25.500021+00:00 | 2023-08-17T17:22:25.500047+00:00 | 62 | false | \nYou first greedily take all top profit values and get the minimal reasonable numCathegories. Then you increase the number of cathegories while removing the worst (lowest) profits.\n\nOnly one structure `cat2count`: number of elements of a given cathegory in the current set.\n\n# Code\n```\ndef findMaximumElegance(sel... | 2 | 0 | ['Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ Solution | c-solution-by-wizard_of_orz-y02p | Approach\n Describe your approach to solving the problem. \nSort all items according to profit from greatest to least.\n\nEnumerate the first K items, and if an | Wizard_of_Orz | NORMAL | 2023-08-06T16:53:22.585069+00:00 | 2023-08-08T01:57:46.703041+00:00 | 112 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nSort all items according to profit from greatest to least.\n\nEnumerate the first K items, and if an item\'s category has already appeared before, push the profit of that item into a priority queue.\n\nYou want to enumerate the rest of the items, and ... | 2 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ Easy Solution || Sort by Profit || Commented code | c-easy-solution-sort-by-profit-commented-qw5m | Intuition\n Describe your first thoughts on how to solve this problem. \nSort items based on decreasing order of profits and take k elements which leads to maxi | tathagata_roy | NORMAL | 2023-08-06T08:03:53.129431+00:00 | 2023-08-06T08:05:00.202724+00:00 | 109 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort items based on decreasing order of profits and take k elements which leads to maximize elegance.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time co... | 2 | 0 | ['Hash Table', 'Sorting', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | [C++] Sorting + Greedy Analysis | c-sorting-greedy-analysis-by-celonymire-ovws | Intuition\n Describe your first thoughts on how to solve this problem. \nWe have two dimensions to this problem at first:\n1. We want to maximize the profit\n2. | CelonyMire | NORMAL | 2023-08-06T04:41:19.975908+00:00 | 2023-08-06T04:41:19.975926+00:00 | 176 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe have two dimensions to this problem at first:\n1. We want to maximize the profit\n2. We want as many distinct categories as possible\n\nSo, we will look for a way to remove one of the dimensions. **We sort the array by non-increasing o... | 2 | 0 | ['Hash Table', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 1 |
maximum-elegance-of-a-k-length-subsequence | [Python3] Sorting + Binary search on the number of different categories | python3-sorting-binary-search-on-the-num-5g71 | [Edit : This worked on all testcases during contest but @canlong found a testcase that my algorithm does not work on]\n\n# Intuition\nThe elegance as a function | Berthouille | NORMAL | 2023-08-06T04:07:59.149905+00:00 | 2023-08-08T18:38:15.367454+00:00 | 395 | false | [Edit : This worked on all testcases during contest but @canlong found a testcase that my algorithm does not work on]\n\n# Intuition\nThe elegance as a function of the number of distinct categories should look like a mountain with a peak.\n\n# Approach\nBinary search the number of distinct categories by checking the el... | 2 | 0 | ['Binary Search', 'Sorting', 'Python3'] | 5 |
maximum-elegance-of-a-k-length-subsequence | 💥💥 Beats 100% on runtime and memory [EXPLAINED] | beats-100-on-runtime-and-memory-explaine-ccdh | IntuitionThe goal is to pick up to k items that maximize the sum of profits while ensuring we get the most distinct categories. If multiple items belong to the | r9n | NORMAL | 2025-01-07T03:27:31.762591+00:00 | 2025-01-07T03:27:31.762591+00:00 | 12 | false | # Intuition
The goal is to pick up to k items that maximize the sum of profits while ensuring we get the most distinct categories. If multiple items belong to the same category, only one of them can be included. To balance between maximizing the profit and respecting the category constraint, we must carefully manage ho... | 1 | 0 | ['Array', 'Hash Table', 'Dynamic Programming', 'Stack', 'Greedy', 'Breadth-First Search', 'Sorting', 'Heap (Priority Queue)', 'Quickselect', 'C#'] | 0 |
maximum-elegance-of-a-k-length-subsequence | JS solution | js-solution-by-aastha_b-hlua | \n\n# Code\n\n/**\n * @param {number[][]} items\n * @param {number} k\n * @return {number}\n */\nvar findMaximumElegance = function (items, k) {\n items.sort | aastha_b | NORMAL | 2024-05-18T09:43:41.487832+00:00 | 2024-05-18T09:43:41.487875+00:00 | 3 | false | \n\n# Code\n```\n/**\n * @param {number[][]} items\n * @param {number} k\n * @return {number}\n */\nvar findMaximumElegance = function (items, k) {\n items.sort((a, b) => b[0] - a[0]);\n let minHeap =... | 1 | 0 | ['JavaScript'] | 1 |
maximum-elegance-of-a-k-length-subsequence | 100% beat || Priority Queue simple solution || O(n.logn) | 100-beat-priority-queue-simple-solution-xlc4c | \n\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n.logn)\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO | Priyanshu_pandey15 | NORMAL | 2024-05-17T05:31:06.910523+00:00 | 2024-05-17T05:31:06.910554+00:00 | 22 | false | \n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n.logn)$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```... | 1 | 0 | ['Java'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Just Sort and Take first K || Take remaining non Duplicates | just-sort-and-take-first-k-take-remainin-he19 | Java []\nclass Solution {\n public long findMaximumElegance(int[][] items, int k) {\n Arrays.sort(items, (a,b)-> b[0]-a[0]);\n Stack<Integer> d | Lil_ToeTurtle | NORMAL | 2023-09-20T04:11:28.705333+00:00 | 2023-09-20T04:11:28.705360+00:00 | 59 | false | ```Java []\nclass Solution {\n public long findMaximumElegance(int[][] items, int k) {\n Arrays.sort(items, (a,b)-> b[0]-a[0]);\n Stack<Integer> duplicates=new Stack<>();\n HashSet<Integer> selected_cats=new HashSet<>(k);\n\n long total_profit=0, elegance=0, size;\n for(int i=0;i<i... | 1 | 0 | ['Stack', 'Ordered Set', 'Java'] | 1 |
maximum-elegance-of-a-k-length-subsequence | Heap/Priority_queue code with comments easy to understand. | heappriority_queue-code-with-comments-ea-71rq | Intuition\n\n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(n)\n\n# Code | vivekkumar1712 | NORMAL | 2023-08-14T13:13:48.236602+00:00 | 2023-08-14T13:13:48.236630+00:00 | 41 | false | # Intuition\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n n=len(items)\n items = sorted(items, ... | 1 | 0 | ['Heap (Priority Queue)', 'Python3'] | 1 |
maximum-elegance-of-a-k-length-subsequence | Solution in Swift | solution-in-swift-by-sergeyleschev-hile | Intuition\nThe approach involves sorting the "items" array in descending order based on the "profiti". By selecting the first "k" items, we ensure that we attai | sergeyleschev | NORMAL | 2023-08-12T06:08:16.651514+00:00 | 2023-08-12T06:08:38.680680+00:00 | 3 | false | # Intuition\nThe approach involves sorting the "items" array in descending order based on the "profiti". By selecting the first "k" items, we ensure that we attain the highest possible "total_profit".\n\n# Approach\nUpon the selection of the initial "k" items, attention turns to the remaining "n - k" items. The viabili... | 1 | 0 | ['Swift'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Java | java-by-tetttet-drz9 | 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 | tetttet | NORMAL | 2023-08-09T13:42:26.970371+00:00 | 2023-08-09T13:42:26.970393+00:00 | 41 | false | # 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)$$ --... | 1 | 0 | ['Java'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Sorting + Traverse + Stack | O(n log n) time, O(n) space | sorting-traverse-stack-on-log-n-time-on-cfipu | Intuition\n Describe your first thoughts on how to solve this problem. \nTo find the maximum elegance of a subsequence with exactly k items, we need to maximize | xun6000 | NORMAL | 2023-08-08T01:35:10.454040+00:00 | 2023-08-08T01:35:10.454067+00:00 | 21 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo find the maximum elegance of a subsequence with exactly **k** items, we need to maximize both the profit and the distinct categories. We can start by selecting the items with the top **k** profits and then explore the possibility of re... | 1 | 0 | ['Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Greedy Solution || C++ | greedy-solution-c-by-ayumsh-prtt | Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(n*log(n))\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(n)\ | ayumsh | NORMAL | 2023-08-07T20:27:25.964789+00:00 | 2023-08-07T20:27:41.051712+00:00 | 22 | false | # Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n*log(n))$$\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n# Code\n```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(it... | 1 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Priority_Queue | C++ | Sorting | priority_queue-c-sorting-by-prabhu_2020-x2cq | Intuition\nWe need the highest profits with unique categories, but there can also be cases where having duplicate categories give us a higher elegance value if | prabhu_2020 | NORMAL | 2023-08-07T07:03:08.395461+00:00 | 2023-08-07T07:03:08.395489+00:00 | 373 | false | # Intuition\nWe need the highest profits with unique categories, but there can also be cases where having duplicate categories give us a higher elegance value if they have big enough profit.\n\n# Approach\nSort by descending order of profits, then take first k elements and after that keep replacing the smallest profit ... | 1 | 0 | ['Greedy', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Easy Java Solution | easy-java-solution-by-prakhar3agrwal-dcq5 | \nclass Solution {\n public long findMaximumElegance(int[][] items, int k) {\n long ans = 0;\n Arrays.sort(items, (a,b)-> b[0]-a[0]);\n | prakhar3agrwal | NORMAL | 2023-08-06T15:34:04.444758+00:00 | 2023-08-06T15:34:04.444790+00:00 | 33 | false | ```\nclass Solution {\n public long findMaximumElegance(int[][] items, int k) {\n long ans = 0;\n Arrays.sort(items, (a,b)-> b[0]-a[0]);\n Set<Integer> categoriesSeen = new HashSet<>();\n List<Integer> duplicateCategories = new ArrayList<>();\n for(int i=0;i<k;i++){\n an... | 1 | 0 | ['Ordered Set', 'Java'] | 1 |
maximum-elegance-of-a-k-length-subsequence | C++| Priority Queue Solution | c-priority-queue-solution-by-coder3484-g4q7 | Code\n\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n int n = items.size();\n sort(items.beg | coder3484 | NORMAL | 2023-08-06T13:10:51.597592+00:00 | 2023-08-06T13:10:51.597616+00:00 | 40 | false | # Code\n```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n int n = items.size();\n sort(items.begin(), items.end(), greater<vector<int>>{}); // greater profit to least\n\n long long distinct = 0, total = 0;\n vector<int> count(n+1, 0);\n ... | 1 | 0 | ['Sorting', 'Heap (Priority Queue)', 'Counting', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | ✅C++ Intuitive solution || ✍️Commented code || | c-intuitive-solution-commented-code-by-j-weet | \n# Code\n\nclass Solution {\npublic:\n bool static cmp(vector<int> &v1,vector<int> &v2){\n return v1[0]>v2[0];\n }\n \n long long findMaximu | JainWinn | NORMAL | 2023-08-06T04:53:19.536365+00:00 | 2023-08-06T04:53:19.536382+00:00 | 247 | false | \n# Code\n```\nclass Solution {\npublic:\n bool static cmp(vector<int> &v1,vector<int> &v2){\n return v1[0]>v2[0];\n }\n \n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n int n=items.size();\n\n //stores initially taken items\n priority_queue<pair<long long,... | 1 | 0 | ['Sorting', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Python, Hash Table, Sorting with comments | python-hash-table-sorting-with-comments-s32ss | Intuition\nWe separate each item according to their categories.\nWe separete the largest of each category to their own list.\nWe sort the lists to find the smal | FransV | NORMAL | 2023-08-06T04:23:45.078072+00:00 | 2023-08-06T04:23:45.078090+00:00 | 96 | false | # Intuition\nWe separate each item according to their categories.\nWe separete the largest of each category to their own list.\nWe sort the lists to find the smallest items of each list\nWe compare the smallest values of each list to each other removing the smaller until we are left with k items. \nIn these comparisons... | 1 | 0 | ['Hash Table', 'Greedy', 'Sorting', 'Python3'] | 1 |
maximum-elegance-of-a-k-length-subsequence | Explained Greedy | Clean Code | 19ms | explained-greedy-clean-code-19ms-by-ivan-xwnu | IntuitionBalance between maximizing profit and distinct category count by first prioritizing unique categories, then swapping low-profit unique items with high- | ivangnilomedov | NORMAL | 2025-03-29T14:14:54.153478+00:00 | 2025-03-29T14:14:54.153478+00:00 | 3 | false | # Intuition
Balance between maximizing profit and distinct category count by first prioritizing unique categories, then swapping low-profit unique items with high-profit duplicates.
# Approach
1. **Sort items by profit** (descending) to prioritize high-value items
2. **First phase**: Greedily select items with distinc... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Python (Simple Maths) | python-simple-maths-by-rnotappl-st1z | 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 | rnotappl | NORMAL | 2024-11-28T06:54:20.619042+00:00 | 2024-11-28T06:54:20.619076+00:00 | 5 | false | # 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)$$ --... | 0 | 0 | ['Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Sort-greedy-two pointer solution | sort-greedy-two-pointer-solution-by-w100-jjn9 | Intuition\n Describe your first thoughts on how to solve this problem. \nFirst idea was to use a DP approach in O(n^2). Fortunately, by checking the constraints | w100roger | NORMAL | 2024-10-26T09:07:39.627319+00:00 | 2024-10-26T09:07:39.627351+00:00 | 0 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst idea was to use a DP approach in $$O(n^2)$$. Fortunately, by checking the constraints I hinted at the fact that this might not work and a greedy approach might be more interesting.\nIt is clear that if a number is maximal and its ca... | 0 | 0 | ['Python'] | 0 |
maximum-elegance-of-a-k-length-subsequence | weird sol but works | weird-sol-but-works-by-anikets2002-ecuv | \n\n# Code\ncpp []\nclass Solution {\npublic:\n\n\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n unordered_set<int> cats;\n | anikets2002 | NORMAL | 2024-10-05T13:59:26.143143+00:00 | 2024-10-05T13:59:26.143166+00:00 | 2 | false | \n\n# Code\n```cpp []\nclass Solution {\npublic:\n\n\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n unordered_set<int> cats;\n multimap<int, int, greater<int>> mp;\n for(auto &x : items)\n {\n mp.insert({x[0], x[1]});\n cats.insert(x[1]);\n ... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Swift: Beats 100% || TC - O(n * log n) || SC - O(n) | swift-beats-100-tc-on-log-n-sc-on-by-ash-b37a | Approach\n1. Arrange items by profits in decreasing order.\n2. Sum k most profitable items in sorted array.\n3. After kth item check if we have visited any dupl | ashish-badak | NORMAL | 2024-08-30T17:43:02.682443+00:00 | 2024-08-30T17:43:02.682470+00:00 | 0 | false | # Approach\n1. Arrange items by profits in decreasing order.\n2. Sum `k` most profitable items in sorted array.\n3. After `k`th item check if we have visited any duplicate category. If no then we have already visited `k` most profitable items with unique categories. We have found our answer.\n4. If we have visited dupl... | 0 | 0 | ['Array', 'Hash Table', 'Swift', 'Sorting'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Simple Hash Table Solution | simple-hash-table-solution-by-rajatktanw-b8ru | Intuition\n Describe your first thoughts on how to solve this problem. \nDp won\'t work with O(n^2) so choose greedy\nMaximize profit and distinct categories\n\ | rajatktanwar | NORMAL | 2024-07-01T07:02:02.971308+00:00 | 2024-07-01T07:02:02.971342+00:00 | 6 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDp won\'t work with $$O(n^2)$$ so choose greedy\nMaximize profit and distinct categories\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst maximize profit by selecting k max-profit elements, then check if elega... | 0 | 0 | ['Hash Table', 'Greedy', 'Sorting', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Warning | Don't watch this | 😓 | warning-dont-watch-this-by-anas10005-3gqy | 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 | Anas10005 | NORMAL | 2024-06-16T17:04:53.216839+00:00 | 2024-06-16T17:05:51.112621+00:00 | 10 | false | # 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:$$O(n*log(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\n<!-- Add your space complexity... | 0 | 0 | ['Hash Table', 'Ordered Map', 'Heap (Priority Queue)', 'Java'] | 0 |
maximum-elegance-of-a-k-length-subsequence | c++ solution | c-solution-by-dilipsuthar60-2r3x | \nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& item, int k) {\n long long ans=0;\n int size=item.size();\n | dilipsuthar17 | NORMAL | 2024-06-15T17:18:58.904371+00:00 | 2024-06-15T17:18:58.904392+00:00 | 2 | false | ```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& item, int k) {\n long long ans=0;\n int size=item.size();\n sort(item.begin(),item.end(),[&](auto &a,auto &b){return a[0]>b[0];});\n unordered_set<int>seen;\n vector<int>duplicateProfit;\n lo... | 0 | 0 | ['C', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Easy Solution | | Using C++ | easy-solution-using-c-by-arbaz_nitp-ssi4 | 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 | Arbaz_nitp | NORMAL | 2024-06-15T09:33:06.975839+00:00 | 2024-06-15T09:33:06.975869+00:00 | 3 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | java solution with time complexity:O(n.logn) Space complexity:O(n) | java-solution-with-time-complexityonlogn-wqih | class Solution {\n public long findMaximumElegance(int[][] arr, int k) {\n int n = arr.length;\n long s = 0, ms = 0, distinct = 0;\n int | sumanth_gonal | NORMAL | 2024-06-15T09:00:02.304468+00:00 | 2024-06-15T09:00:02.304505+00:00 | 0 | false | class Solution {\n public long findMaximumElegance(int[][] arr, int k) {\n int n = arr.length;\n long s = 0, ms = 0, distinct = 0;\n int[] freq = new int[n + 1];\n Arrays.sort(arr, (a, b) -> b[0] - a[0]);\n PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> a[0] - b[0]);\n ... | 0 | 0 | [] | 0 |
maximum-elegance-of-a-k-length-subsequence | Easy to understand c++ | easy-to-understand-c-by-mahakaal89-2i3w | Intuition\n Describe your first thoughts on how to solve this problem. \nfirst maximum then max no of distinct catagory.\n\n# Approach\n Describe your approach | Mahakaal89 | NORMAL | 2024-06-15T03:53:56.584588+00:00 | 2024-06-15T03:53:56.584615+00:00 | 1 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nfirst maximum then max no of distinct catagory.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.first calculate k max profitable item.and if duplicate catagory found store it in a vector;\n\n2.then traverse if ca... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ greedy | c-greedy-by-wufengxuan1230-hviy | \nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(items.begin(), items.end(), [&](const vector<i | wufengxuan1230 | NORMAL | 2024-06-13T14:55:28.009717+00:00 | 2024-06-13T14:55:28.009784+00:00 | 2 | false | ```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(items.begin(), items.end(), [&](const vector<int>& a, const vector<int>& b) {\n return a[0] > b[0];\n });\n\n unordered_set<int> m;\n stack<int> s;\n long long maxE... | 0 | 0 | [] | 0 |
maximum-elegance-of-a-k-length-subsequence | Hash and qsort to sovle this issue | hash-and-qsort-to-sovle-this-issue-by-sq-g6y9 | 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 | squall1207 | NORMAL | 2024-06-13T14:43:18.193494+00:00 | 2024-06-13T14:43:18.193524+00:00 | 0 | false | # 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)$$ --... | 0 | 0 | ['Hash Table', 'C', 'Sorting'] | 0 |
maximum-elegance-of-a-k-length-subsequence | 🔥 Go Solution | Greedy | Beat 100% | With Explanation🔥 | go-solution-greedy-beat-100-with-explana-eeca | Intuition\nGreedy with regret.\n\n# Approach\nSort the items by profit in descending order and initially select the first k projects. Then, scan through the rem | ConstantineJin | NORMAL | 2024-06-13T03:24:16.335767+00:00 | 2024-06-13T03:24:16.335807+00:00 | 2 | false | # Intuition\nGreedy with regret.\n\n# Approach\nSort the `items` by profit in descending order and initially select the first `k` projects. Then, scan through the remaining `items` linearly and assess whether selecting `items[i]` can increase the value of `ans`. During the process, we need to deselect a previously sele... | 0 | 0 | ['Hash Table', 'Stack', 'Greedy', 'Sorting', 'Go'] | 0 |
maximum-elegance-of-a-k-length-subsequence | greedy Sorting + heap + hashtable python3 | greedy-sorting-heap-hashtable-python3-by-1w8p | \n\n# Code\n\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n items.sort(reverse = True)\n items = [t | MaxOrgus | NORMAL | 2024-06-01T15:11:58.895506+00:00 | 2024-06-01T15:11:58.895534+00:00 | 6 | false | \n\n# Code\n```\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n items.sort(reverse = True)\n items = [tuple(t) for t in items]\n freq = {}\n heap = []\n sumpf = 0\n categories = 0\n res = 0\n for i,(p,c) in enumerate(i... | 0 | 0 | ['Hash Table', 'Greedy', 'Sorting', 'Heap (Priority Queue)', 'Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | JS MinHeap Clean Solution | js-minheap-clean-solution-by-nanlyn-bs9w | 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 | nanlyn | NORMAL | 2024-05-01T17:37:36.064412+00:00 | 2024-05-01T17:37:36.064436+00:00 | 1 | false | # 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)$$ --... | 0 | 0 | ['JavaScript'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Greedy | Stack | No Heap or Priority Queue | greedy-stack-no-heap-or-priority-queue-b-edpw | Approach\nSort by profit from largest to smallest, and take the top k items. If there is already k different categories, we find the best possible profit. Other | popzkk | NORMAL | 2024-04-20T00:58:35.911956+00:00 | 2024-04-20T00:58:35.911981+00:00 | 6 | false | # Approach\nSort by profit from largest to smallest, and take the top $$k$$ items. If there is already $$k$$ different categories, we find the best possible profit. Otherwise, we try to increase the number of categories and record each new total profit as we increase the catrgories.\n\nEvery time when we have a candida... | 0 | 0 | ['Array', 'Stack', 'Greedy', 'Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Try all but update incrementally | try-all-but-update-incrementally-by-lamb-yxv3 | Intuition\n- Sort items with deceasing profit, and choose the first k items.\n- This gives baseline answer ans, with # categories = c\n- Increase c step by step | lambdacode-dev | NORMAL | 2024-04-11T21:01:06.790523+00:00 | 2024-04-11T21:01:06.790550+00:00 | 0 | false | # Intuition\n- Sort `items` with deceasing profit, and choose the first `k` items.\n- This gives baseline answer `ans`, with `# categories` = `c`\n- Increase `c` step by step up to `c = k`, while updating `ans` incrementally.\n- To do incremental update, replace the worst that is already in `ans` and **replaceable**, b... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Python - WITH & WITHOUT A HEAP ✅ | python-with-without-a-heap-by-itsarvindh-56le | The elegance of a subsequence is given as - \n\n\ttotal_profit + distinct_categories^2\n\t\nThis means, for the maximum elegance, we need to maximize not just t | itsarvindhere | NORMAL | 2024-02-09T11:36:58.654115+00:00 | 2024-02-09T11:42:29.232798+00:00 | 4 | false | The elegance of a subsequence is given as - \n\n\ttotal_profit + distinct_categories^2\n\t\nThis means, for the maximum elegance, we need to maximize not just the profit, but also the distinct categories. Ofcourse it is not always possible that both are maximized at the same time so we want to balance them such that th... | 0 | 0 | ['Sorting', 'Heap (Priority Queue)', 'Ordered Set', 'Python'] | 0 |
maximum-elegance-of-a-k-length-subsequence | O(NlogN) greedy solution. | onlogn-greedy-solution-by-leeyongs-uut0 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Sort items by descen | leeyongs | NORMAL | 2024-01-20T18:14:14.691177+00:00 | 2024-01-20T18:14:14.691229+00:00 | 6 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Sort items by descending order of profit.\n2. Add top K items. As we add items, keep the minimum profit per category where it has more than one element (since throw... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Simple intution based question | simple-intution-based-question-by-sunnyk-z6oa | 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 | sunnykumarbr85 | NORMAL | 2024-01-16T10:57:21.204482+00:00 | 2024-01-16T10:57:21.204509+00:00 | 6 | false | # 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)$$ --... | 0 | 0 | ['Sorting', 'Ordered Set', 'Java'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ | c-by-tinachien-uvo8 | \nusing LL = long long;\nusing PII = pair<LL, LL>;\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n s | TinaChien | NORMAL | 2023-12-09T09:31:11.735876+00:00 | 2023-12-09T09:31:11.735905+00:00 | 1 | false | ```\nusing LL = long long;\nusing PII = pair<LL, LL>;\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(items.rbegin(), items.rend());\n LL sum = 0;\n unordered_map<int, int>Map; //[category, count]\n for(int i = 0; i < k; i++){\n ... | 0 | 0 | [] | 0 |
maximum-elegance-of-a-k-length-subsequence | Solution in C | solution-in-c-by-liamtrudel2008-zony | Intuition\nInitially, one might consider using a dynamic programming approach to solve this problem, as it involves optimizing a certain value (elegance) across | liamtrudel2008 | NORMAL | 2023-11-18T23:24:08.569977+00:00 | 2023-11-18T23:24:08.569996+00:00 | 3 | false | # Intuition\nInitially, one might consider using a dynamic programming approach to solve this problem, as it involves optimizing a certain value (elegance) across a subset of elements (items). However, the key insight is that a greedy approach can be more efficient. We aim to maximize the sum of profits while also maxi... | 0 | 0 | ['C'] | 0 |
maximum-elegance-of-a-k-length-subsequence | 2813. Maximum Elegance of a K-Length Subsequence | 2813-maximum-elegance-of-a-k-length-subs-51kq | ```\nclass Solution {\n public:\n long long findMaximumElegance(vector>& items, int k) {\n long long ans = 0;\n long long totalProfit = 0;\n // Store | abhirajgautam2 | NORMAL | 2023-11-01T13:22:37.170729+00:00 | 2023-11-01T13:22:37.170768+00:00 | 4 | false | ```\nclass Solution {\n public:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n long long ans = 0;\n long long totalProfit = 0;\n // Store seen categories.\n unordered_set<int> seenCategories;\n // Store duplicate profits decreasingly.\n stack<int> decreasingDuplicateProfits;\n... | 0 | 0 | ['Hash Table'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Just a runnable solution | just-a-runnable-solution-by-ssrlive-st3w | \n\nimpl Solution {\n pub fn find_maximum_elegance(items: Vec<Vec<i32>>, k: i32) -> i64 {\n let mut items = items\n .iter()\n .m | ssrlive | NORMAL | 2023-10-17T08:51:40.228246+00:00 | 2023-10-17T09:07:01.634428+00:00 | 3 | false | \n```\nimpl Solution {\n pub fn find_maximum_elegance(items: Vec<Vec<i32>>, k: i32) -> i64 {\n let mut items = items\n .iter()\n .map(|v| v.iter().map(|&x| x as i64).collect::<Vec<_>>())\n .collect::<Vec<_>>();\n let k = k as usize;\n items.sort_unstable_by(|a, b... | 0 | 0 | ['Rust'] | 0 |
maximum-elegance-of-a-k-length-subsequence | GO || without priority_queue | go-without-priority_queue-by-mohaldarpra-c6pk | \n\nfunc max64(a, b int64) int64 {\n\tif a > b {\n\t\treturn a\n\t}\n\treturn b\n}\nfunc findMaximumElegance(items [][]int, k int) int64 {\n sort.Slice(items | mohaldarprakash | NORMAL | 2023-08-31T07:12:18.895827+00:00 | 2023-08-31T07:12:18.895849+00:00 | 2 | false | \n```\nfunc max64(a, b int64) int64 {\n\tif a > b {\n\t\treturn a\n\t}\n\treturn b\n}\nfunc findMaximumElegance(items [][]int, k int) int64 {\n sort.Slice(items, func (i,j int) bool{\n return items[i][0]>items[j][0]\n })\n\n mp := make(map[int]int)\n\n sum := int64(0)\n for i:=0; i<k; i++{\n ... | 0 | 0 | ['Go'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Golang simple soluation | golang-simple-soluation-by-user8775po-u6fz | 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 | user8775Po | NORMAL | 2023-08-29T17:52:04.382366+00:00 | 2023-08-29T17:52:04.382388+00:00 | 2 | false | # 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)$$ --... | 0 | 0 | ['Go'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Sorting + Greedy | sorting-greedy-by-dnitin28-5pgn | \n# Code\n\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& v, int k) {\n int n = v.size();\n sort(v.begin(), v. | gyrFalcon__ | NORMAL | 2023-08-28T05:42:58.681441+00:00 | 2023-08-28T05:42:58.681458+00:00 | 7 | false | \n# Code\n```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& v, int k) {\n int n = v.size();\n sort(v.begin(), v.end(), greater<vector<int>>());\n long long ans = 0, answer = 0;\n vector<int> duplicate;\n set<int> visited;\n for(int i=0;i<n;i... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | [C/C++/Python] Detailed description and comments. O(nlogn) time, O(n) space | ccpython-detailed-description-and-commen-6z8p | Intuition\nThe problem calls for picking the best of two disconnected values, the number of categories and the total of the profits. My immediate thought was th | christrompf | NORMAL | 2023-08-17T13:18:12.764872+00:00 | 2023-08-18T00:39:03.445191+00:00 | 13 | false | # Intuition\nThe problem calls for picking the best of two disconnected values, the number of categories and the total of the profits. My immediate thought was that starting at one extreme and working towards the other will produced the answer.\n\nStart with maximising the profits by selecting the _k_ most profitable a... | 0 | 0 | ['C', 'Python', 'C++', 'Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Greedy Algorithm || C++ | greedy-algorithm-c-by-igloo11-zpqp | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nGreedy Algorithm\n\n# C | Igloo11 | NORMAL | 2023-08-17T08:26:34.510082+00:00 | 2023-08-17T08:26:34.510105+00:00 | 11 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nGreedy Algorithm\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... | 0 | 0 | ['Hash Table', 'Stack', 'Greedy', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Not elegant, but effective | not-elegant-but-effective-by-fredrick_li-5pbs | Code\n\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n cat = {}\n hp = []\n for val,c in item | Fredrick_LI | NORMAL | 2023-08-14T16:10:29.888565+00:00 | 2023-08-14T16:10:29.888593+00:00 | 5 | false | # Code\n```\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n cat = {}\n hp = []\n for val,c in items:\n if c not in cat:\n cat[c] = val\n elif cat[c] < val:\n heappush(hp,-cat[c])\n cat[c... | 0 | 0 | ['Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | set + deque solution c++ | set-deque-solution-c-by-dan_zhixu-nbqn | Intuition\nThe elegance is a condition on both profit and category, but to simplify the problem, we can first get the maximum subsequence on profit, and improve | dan_zhixu | NORMAL | 2023-08-13T16:10:08.724628+00:00 | 2023-08-13T16:10:08.724646+00:00 | 5 | false | # Intuition\nThe elegance is a condition on both profit and category, but to simplify the problem, we can first get the maximum subsequence on profit, and improve it on the category. \n\n# Approach\n1. Sort the items by profit. So the first k items are the subsequence with maximum profits. \n2. If the first k items\' c... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ | greedy | c-greedy-by-ouasintheden-u0dv | \n# Code\n\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(items.rbegin(), items.rend());\n | ouasintheden | NORMAL | 2023-08-13T08:55:09.897896+00:00 | 2023-08-13T08:55:09.897921+00:00 | 8 | false | \n# Code\n```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(items.rbegin(), items.rend());\n long long profitSum = 0, ans = 0, res = 0;\n unordered_map<int,int> categoreis, dup;\n for(int i = 0 ; i < k;i++){\n profitSum +... | 0 | 0 | ['Greedy', 'Sorting', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | c# sort + replace repeated category item one by one | c-sort-replace-repeated-category-item-on-vfov | Intuition and Approach\n To get the result , we need try to select item with larger profit. The best situation is items with first largest profile are with diff | julian_meng_chang | NORMAL | 2023-08-12T20:46:45.670859+00:00 | 2023-08-12T20:46:45.670882+00:00 | 9 | false | # Intuition and Approach\n To get the result , we need try to select item with larger profit. The best situation is items with first largest profile are with different profit.\nThen sort the items according to profit.\nWe start from first k elements, and record all items with repeated category with a Stack. The element... | 0 | 0 | ['C#'] | 0 |
maximum-elegance-of-a-k-length-subsequence | [Python3] Sort by profit and use math | python3-sort-by-profit-and-use-math-by-n-ziwu | We can track everything in a single variable current and keep it updated by using the fact that (x^2) - ((x-1)^2) = 2x-1\n\npython\nclass Solution:\n def fin | nottheswimmer | NORMAL | 2023-08-11T11:59:34.114244+00:00 | 2023-08-11T12:00:32.534754+00:00 | 8 | false | We can track everything in a single variable `current` and keep it updated by using the fact that (x^2) - ((x-1)^2) = 2x-1\n\n```python\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n best = current = 0\n seen = set()\n skipped = []\n items.sort(... | 0 | 0 | [] | 0 |
maximum-elegance-of-a-k-length-subsequence | Why the STRIVER approach didn't work ?? | why-the-striver-approach-didnt-work-by-g-gixj | class Solution {\npublic:\n \n long long solve(vector>&items , int n , int i , int k , map&m , int cnt)\n {\n if(i==n || cnt>k) return 0;\n | gauti1309 | NORMAL | 2023-08-11T06:57:58.223449+00:00 | 2023-08-11T06:57:58.223482+00:00 | 68 | false | class Solution {\npublic:\n \n long long solve(vector<vector<int>>&items , int n , int i , int k , map<int,int>&m , int cnt)\n {\n if(i==n || cnt>k) return 0;\n \n m[items[i][1]]++;\n \n long long pick=solve(items , n , i+1 , k , m , cnt+1) + (items[i][0] + pow(m.size() , 2))... | 0 | 0 | ['Dynamic Programming', 'Greedy', 'C++'] | 3 |
maximum-elegance-of-a-k-length-subsequence | [C++] 2 Segment Tree Easy to understand | c-2-segment-tree-easy-to-understand-by-c-j0tr | Code\n\nvoid update(vector<long long> &seg, int start, int end, int pos, int node, long long val){\n if(start > pos || end < pos){\n return;\n }\n | caobaohoang03 | NORMAL | 2023-08-10T23:50:59.364106+00:00 | 2023-08-10T23:50:59.364133+00:00 | 10 | false | # Code\n```\nvoid update(vector<long long> &seg, int start, int end, int pos, int node, long long val){\n if(start > pos || end < pos){\n return;\n }\n if(start == end){\n seg[node] += val;\n return;\n }\n int mid = (start+end)/2;\n \n update(seg, start, mid, pos, node*2+1, val... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Easy and Intuitive Python soln🔥 | easy-and-intuitive-python-soln-by-ebadd-he61 | Intuition\n Describe your first thoughts on how to solve this problem. \ngreedy\n# Approach\n Describe your approach to solving the problem. \nsort w.r.t profit | ebadd | NORMAL | 2023-08-09T10:45:03.768090+00:00 | 2023-08-09T10:45:03.768111+00:00 | 14 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ngreedy\n# Approach\n<!-- Describe your approach to solving the problem. -->\nsort w.r.t profit from higher to lower. Take the first K element. \nmake a dp to store the number of times each category occured.\nif all the category are differ... | 0 | 0 | ['Sorting', 'Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | simple greedy with stack | simple-greedy-with-stack-by-rip-7dzl | Intuition\n\n\n# Approach\nget first k most profitable items, than try to increase numbers of unique catigories by dropping less profitable items.\n\n# Complexi | rip | NORMAL | 2023-08-08T17:13:04.578589+00:00 | 2023-08-08T17:38:33.428281+00:00 | 9 | false | # Intuition\n\n\n# Approach\nget first k most profitable items, than try to increase numbers of unique catigories by dropping less profitable items.\n\n# Complexity\n- Time complexity:\n$$O(log(n)*n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<v... | 0 | 0 | ['Greedy', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | || CPP || 💡 Track the repeating using stack, Hashing very simple implementaion. | cpp-track-the-repeating-using-stack-hash-zlc4 | Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) \nO(nlogn)\n- Space complexity:\n Add your space complexity here, e.g. O(n) \nO(n)\n# | LikeTheSun14 | NORMAL | 2023-08-08T05:30:00.431398+00:00 | 2023-08-08T05:30:00.431425+00:00 | 14 | false | # Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n // sort according ... | 0 | 0 | ['Array', 'Hash Table', 'Stack', 'Greedy', 'Sorting', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Stack + Sorting | stack-sorting-by-lwy123177-cd48 | \nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n n = len(items)\n items.sort(reverse=True)\n | lwy123177 | NORMAL | 2023-08-08T00:21:49.540623+00:00 | 2023-08-08T00:21:49.540650+00:00 | 14 | false | ```\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n n = len(items)\n items.sort(reverse=True)\n seen_category = set()\n stk = []\n ans = 0\n for i in range(k):\n profit, cat = items[i]\n ans += profit\n ... | 0 | 0 | ['Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ solution | Priority queues | sorting | c-solution-priority-queues-sorting-by-ra-1psq | \nclass Solution {\npublic:\n unordered_set<int> on;\n unordered_map<int,vector<int>> v;\n unordered_map<int,int> mp;\n priority_queue<array<int,2>> | rac101ran | NORMAL | 2023-08-07T22:40:12.430856+00:00 | 2023-08-07T22:43:41.672971+00:00 | 11 | false | ```\nclass Solution {\npublic:\n unordered_set<int> on;\n unordered_map<int,vector<int>> v;\n unordered_map<int,int> mp;\n priority_queue<array<int,2>> hq;\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n for(int i=0; i<items.size(); i++) {\n v[items[i][1]].push_ba... | 0 | 0 | ['C', 'Sorting'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Python 3 || Explained in detail | python-3-explained-in-detail-by-mayud-0ldo | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\nAs we know we finally | MayuD | NORMAL | 2023-08-07T14:57:50.218542+00:00 | 2023-08-07T14:59:13.468231+00:00 | 10 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nAs we know we finally want to return a sum of all the first elements in an array and square of different number of categories that are the number of different elemen... | 0 | 0 | ['Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ || Using Sorting + Map + Stack || Beats 100% || Easiest Code | c-using-sorting-map-stack-beats-100-easi-8hjp | 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 | hector_21 | NORMAL | 2023-08-07T12:31:27.967692+00:00 | 2023-08-07T12:32:27.775883+00:00 | 12 | false | # 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:\nO(n*log(n))\n\n- Space complexity:\no(n)\n\n# Code\n```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector... | 0 | 0 | ['Stack', 'Ordered Map', 'Sorting', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Easy C++ solution | easy-c-solution-by-mridulkaran2021-mj7s | Intuition\n Describe your first thoughts on how to solve this problem. \nThink Greedy. Take top K elements and find the ans. Now, what factors affect the final | mridulkaran2021 | NORMAL | 2023-08-07T08:29:28.860665+00:00 | 2023-08-07T08:29:28.860684+00:00 | 7 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThink Greedy. Take top K elements and find the ans. Now, what factors affect the final ans? The distinct categories and value of ith element. We just need to optimally choose the elements which increase our ans.\n\n# Approach\n<!-- Descri... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ * 400ms * beats 100% * Track Duplicates | c-400ms-beats-100-track-duplicates-by-co-qbio | Intuition\n Describe your first thoughts on how to solve this problem. \nDP won\'t work, look at the constraints once, I got TLE @ 1487 cases.\nThis problem req | coderpriest | NORMAL | 2023-08-07T02:42:14.391533+00:00 | 2023-08-07T02:42:59.214397+00:00 | 18 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDP won\'t work, look at the constraints once, I got TLE @ 1487 cases.\nThis problem requires Greedy approach.\n# Approach\n<!-- Describe your approach to solving the problem. --> \n1. Sort profit in descending order and take first k profi... | 0 | 0 | ['Stack', 'Sorting', 'Ordered Set', 'C++'] | 1 |
maximum-elegance-of-a-k-length-subsequence | [C++] Group by category, add the most profitable and heap for the remaining | c-group-by-category-add-the-most-profita-yi6x | 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 | phi9t | NORMAL | 2023-08-06T22:33:22.720952+00:00 | 2023-08-06T22:33:22.720982+00:00 | 8 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Maximum Elegance | Easy to Understand | Faster than 100% | maximum-elegance-easy-to-understand-fast-im5a | \n\n# Code\n\nclass Solution {\n public long findMaximumElegance(int[][] items, int k) {\n PriorityQueue<int[]>pq=new PriorityQueue<>((a,b)->a[0]-b[0] | Paridhicodes | NORMAL | 2023-08-06T21:56:54.096867+00:00 | 2023-08-06T22:06:32.118861+00:00 | 31 | false | \n\n# Code\n```\nclass Solution {\n public long findMaximumElegance(int[][] items, int k) {\n PriorityQueue<int[]>pq=new PriorityQueue<>((a,b)->a[0]-b[0]);\n HashSet<Integer> hs=new HashSet<>();\n List<int[]>comp=new ArrayList<>();\n\n Arrays.sort(items,(a,b)->b[0]-a[0]);\n\n int n... | 0 | 0 | ['Java'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Greedy Python + detailed comments | greedy-python-detailed-comments-by-jrry8-uh0s | Intuition\n Describe your first thoughts on how to solve this problem. \nFirst, compute the elegance of the subseq of k items with maximum total profit. \nThen | jrry8 | NORMAL | 2023-08-06T20:53:10.492426+00:00 | 2023-08-06T20:53:10.492449+00:00 | 9 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst, compute the elegance of the subseq of k items with maximum total profit. \nThen we iterate by adding items of the highest profit from new categories while removing items of the lowest profit from duplicate categories. \nIn this pro... | 0 | 0 | ['Greedy', 'Python', 'Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ solution based on provided hints | c-solution-based-on-provided-hints-by-vv-m4kz | \nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, long long k) {\n long long n = items.size();\n sort(items.begin() | vvhack | NORMAL | 2023-08-06T19:29:58.051140+00:00 | 2023-08-06T19:29:58.051164+00:00 | 4 | false | ```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, long long k) {\n long long n = items.size();\n sort(items.begin(), items.end(), [] (const auto& a, const auto& b) {\n return a[0] > b[0];\n });\n long long totProf = 0;\n int lastMultipleIdx = -1;\n unorde... | 0 | 0 | [] | 0 |
maximum-elegance-of-a-k-length-subsequence | Simple Sorting Solution!!⚡⚡🔥 | simple-sorting-solution-by-yashpadiyar4-pcxr | \n\n# Code\n\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(items.begin(),items.end(),[&](vect | yashpadiyar4 | NORMAL | 2023-08-06T18:41:24.225890+00:00 | 2023-08-06T18:41:24.225915+00:00 | 7 | false | \n\n# Code\n```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(items.begin(),items.end(),[&](vector<int>&a,vector<int>&b){\n return a[0]>b[0];\n });\n unordered_set<int>s;\n long long res=0;\n long long ans=0;\n ... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Beats 100 percent time | beats-100-percent-time-by-abhinav_1820-zdlh | Intuition\n\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- | Abhinav_1820 | NORMAL | 2023-08-06T15:51:00.700648+00:00 | 2023-08-06T15:51:00.700686+00:00 | 6 | false | # Intuition\n\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```\nclass Solution {\npublic:\n long long findMaxi... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Using Priority Queue And Map..................................... | using-priority-queue-and-map-by-kumarrar-blli | Intuition\n Describe your first thoughts on how to solve this problem. \nfor maximum profit how you get?.. taking top k elemetns with higher profit no matter (t | kumarrarya | NORMAL | 2023-08-06T15:21:47.093843+00:00 | 2023-08-06T15:21:47.093873+00:00 | 10 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nfor maximum profit how you get?.. taking top k elemetns with higher profit no matter (they belong to same category or not. think in greedy) after that choose that profit which is from differnt category so that our profit maximize so we ca... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Simple Solution using PriorityQueue | simple-solution-using-priorityqueue-by-n-3myf | 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 | nikleetcode | NORMAL | 2023-08-06T15:13:25.935901+00:00 | 2023-08-06T15:13:25.935926+00:00 | 22 | false | # 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: 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... | 0 | 0 | ['Java'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Python Hard | python-hard-by-lucasschnee-306c | \nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n\n categories = set()\n\n count = 0\n\n ans = | lucasschnee | NORMAL | 2023-08-06T14:36:57.767790+00:00 | 2023-08-06T14:36:57.767809+00:00 | 9 | false | ```\nclass Solution:\n def findMaximumElegance(self, items: List[List[int]], k: int) -> int:\n\n categories = set()\n\n count = 0\n\n ans = 0\n\n total_profit = 0\n\n items.sort(key = lambda x: -x[0])\n\n h = []\n\n\n for profit, c in items:\n\n if count < ... | 0 | 0 | ['Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | 100% fastest || Greedy intutive approach complete explanation | 100-fastest-greedy-intutive-approach-com-yy0l | our final goal is to find max profit out of all possible subsequence of k length\nso first thing comes in thought : let\'s sort in decreasing and return sum of | demon_code | NORMAL | 2023-08-06T10:53:41.506375+00:00 | 2023-08-06T10:55:25.455905+00:00 | 10 | false | our final goal is to find max profit out of all possible subsequence of k length\nso first thing comes in thought : let\'s sort in decreasing and return sum of first k elements and in normal condition that would be our best answer but here bcz of addtion of no of squire of unique elements we need to remove some of elem... | 0 | 0 | ['C', 'Sorting'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Greedy + Heap, Select Profit Top-K Then Replace Duplicate Categories | greedy-heap-select-profit-top-k-then-rep-kop2 | 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 | benlegend | NORMAL | 2023-08-06T07:21:43.766184+00:00 | 2023-08-06T07:24:40.360010+00:00 | 20 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ Binary Search + BFS Solution | c-binary-search-bfs-solution-by-solvedor-iz5q | \nclass Solution {\npublic:\n vector<int> delx={-1,1,0,0};\n vector<int> dely={0,0,-1,1};\n bool check(int mid, vector<vector<int>>& dist){\n in | solvedORerror | NORMAL | 2023-08-06T07:15:28.769416+00:00 | 2023-08-06T07:15:28.769439+00:00 | 29 | false | ```\nclass Solution {\npublic:\n vector<int> delx={-1,1,0,0};\n vector<int> dely={0,0,-1,1};\n bool check(int mid, vector<vector<int>>& dist){\n int n=dist.size();\n if(dist[0][0]<mid or dist[n-1][n-1]<mid)return false;\n vector<vector<bool>> vis(n,vector<bool>(n));\n queue<pair<int... | 0 | 0 | ['Breadth-First Search', 'Binary Tree'] | 1 |
maximum-elegance-of-a-k-length-subsequence | Priority_Queue | C++ | Sorting | priority_queue-c-sorting-by-marcos009-i3o0 | Code\n\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(items.begin(),items.end());\n rev | marcos009 | NORMAL | 2023-08-06T06:41:21.329549+00:00 | 2023-08-06T06:41:21.329580+00:00 | 45 | false | # Code\n```\nclass Solution {\npublic:\n long long findMaximumElegance(vector<vector<int>>& items, int k) {\n sort(items.begin(),items.end());\n reverse(items.begin(),items.end());\n priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>p;\n if(k==1){\n retu... | 0 | 0 | ['Heap (Priority Queue)', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Faster but longer solution | faster-but-longer-solution-by-vilmos_pro-jgkp | \n# Complexity\n- Time complexity: O(n\log(n)) due to sorting and the heap.\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n) \n Add your | vilmos_prokaj | NORMAL | 2023-08-06T06:28:35.636689+00:00 | 2023-08-06T06:28:35.636713+00:00 | 18 | false | \n# Complexity\n- Time complexity: $$O(n\\log(n))$$ due to sorting and the heap.\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\n# Code\n```\nclass Solution:\n\n def findMaximumElegance(self, items: List[List[int]], k:... | 0 | 0 | ['Heap (Priority Queue)', 'Python3'] | 0 |
maximum-elegance-of-a-k-length-subsequence | Greedy , take favourable items , well explained Solution✔️✔️✔️✔️ | greedy-take-favourable-items-well-explai-ljod | Approach\n1. The function first sorts the items vector in descending order based on profits. It maintains a set seen to track distinct categories and a vector d | __AKASH_SINGH___ | NORMAL | 2023-08-06T06:28:22.167248+00:00 | 2023-08-06T06:28:22.167274+00:00 | 12 | false | # Approach\n1. The function first sorts the items vector in descending order based on profits. It maintains a set seen to track distinct categories and a vector dup to store duplicate profits encountered in the initial k elements.\n\n2. Then, the function iterates through the sorted items. For the first k elements, it ... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ Solution | Priority_queue | c-solution-priority_queue-by-juggaljain-0wis | 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 | juggaljain | NORMAL | 2023-08-06T06:17:38.192151+00:00 | 2023-08-06T06:18:12.528153+00:00 | 19 | false | # 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)$$ --... | 0 | 0 | ['C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | beats 100%, nlogn sort with explanation | beats-100-nlogn-sort-with-explanation-by-6l6i | Approach\n Describe your approach to solving the problem. \n1) add highest profits with a unique category to a min heap.\n2) if heap is less than k add highest | Id000 | NORMAL | 2023-08-06T06:08:23.150468+00:00 | 2023-08-07T16:31:16.277500+00:00 | 35 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n1) add highest profits with a unique category to a min heap.\n2) if heap is less than k add highest profits that are not unique\n3) loop through remaining values, if any has a profit greater than 2 * (number of unique categories in heap) - 1 + min_pro... | 0 | 0 | ['Java'] | 1 |
maximum-elegance-of-a-k-length-subsequence | Rust/C++ Sorting | rustc-sorting-by-xiaoping3418-rpjx | Intuition\n Describe your first thoughts on how to solve this problem. \n1) Sort the items based on prefit.\n2) Pick one item per category in the descending ord | xiaoping3418 | NORMAL | 2023-08-06T06:05:47.853000+00:00 | 2023-08-06T23:48:40.188026+00:00 | 13 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1) Sort the items based on prefit.\n2) Pick one item per category in the descending order of profit.\n3) While k > 0, picking additional items in the existing categories.\n4) If k == 0, check to see if the smallest item could be replaced ... | 0 | 0 | ['Sorting', 'C++', 'Rust'] | 0 |
maximum-elegance-of-a-k-length-subsequence | My Solution | my-solution-by-hope_ma-aqpn | \n/**\n * Time Complexity: O(n * log(n))\n * Space Complexity: O(n)\n * where `n` is the length of the vector `items`\n */\nclass Solution {\n public:\n long l | hope_ma | NORMAL | 2023-08-06T05:57:02.780616+00:00 | 2023-08-11T14:27:22.030468+00:00 | 6 | false | ```\n/**\n * Time Complexity: O(n * log(n))\n * Space Complexity: O(n)\n * where `n` is the length of the vector `items`\n */\nclass Solution {\n public:\n long long findMaximumElegance(vector<vector<int>> &items, const int k) {\n const int n = static_cast<int>(items.size());\n sort(items.begin(), items.end(), [... | 0 | 0 | [] | 0 |
maximum-elegance-of-a-k-length-subsequence | C++ || Sorting || Map || Set | c-sorting-map-set-by-syphenlm12-zolj | Approach\n1. Sort on the basis of profit in decreasing order.\n2. Now take first k elements and also store that which category occurs how many time.\n3. After k | Syphenlm12 | NORMAL | 2023-08-06T05:53:58.374891+00:00 | 2023-08-06T05:53:58.374909+00:00 | 27 | false | # Approach\n1. Sort on the basis of profit in decreasing order.\n2. Now take first k elements and also store that which category occurs how many time.\n3. After k elements you will add any other number other than k elements if any category occurs more than one times in the k size window remove that element that add thi... | 0 | 0 | ['Ordered Map', 'Sorting', 'Ordered Set', 'C++'] | 0 |
maximum-elegance-of-a-k-length-subsequence | [Java] Greedy solution | java-greedy-solution-by-wddd-8ptj | Intuition\n\nGreedy works here. \n\nIdea: we firstly pick k items with max total profits. Then we gradully/greedily remove some of them and replace with ones in | wddd | NORMAL | 2023-08-06T05:25:25.194199+00:00 | 2023-08-06T05:25:25.194217+00:00 | 28 | false | # Intuition\n\nGreedy works here. \n\nIdea: we firstly pick `k` items with max total profits. Then we gradully/greedily remove some of them and replace with ones in different categories. This way, the `total_profit` decreases, but we are compensated by `distinct_categories^2`, and we may get a bigger elegance value. Ab... | 0 | 0 | ['Java'] | 0 |
minimum-score-by-changing-two-elements | Explained two solutions - with & without sorting || Very Simple & Easy to Understand | explained-two-solutions-with-without-sor-2ihy | Up Vote if you like the solution \n\n# Approach\n\nFirst of all we can simply replace two numbers with the same value, that results in the lowest difference to | kreakEmp | NORMAL | 2023-02-18T16:02:41.477147+00:00 | 2023-02-18T17:05:22.115952+00:00 | 5,605 | false | Up Vote if you like the solution \n\n# Approach\n\nFirst of all we can simply replace two numbers with the same value, that results in the lowest difference to zero in all cases.\nSo now the problem statement becomes, high (max difference) should be lowest. \nSo to achieve this, we need to decrease the difference betwe... | 75 | 1 | ['C++'] | 9 |
minimum-score-by-changing-two-elements | Simple Diagram Explanation | simple-diagram-explanation-by-l30xl1u-kjaq | Idea\n- Sort nums so that we can easily access maximum and minimum values\n- We will always make the low score 0 by creating duplicate values\n- Now we have cha | L30XL1U | NORMAL | 2023-02-18T20:00:42.079714+00:00 | 2023-02-18T20:04:57.246329+00:00 | 1,780 | false | # Idea\n- Sort `nums` so that we can easily access maximum and minimum values\n- We will always make the low score $$0$$ by creating duplicate values\n- Now we have changed the question to finding the minimum maximum value difference by changing two values\n- We have three options:\n - Change the two largest values ... | 54 | 0 | ['C++', 'Java', 'Python3'] | 3 |
minimum-score-by-changing-two-elements | [Java/C++/Python] Change Biggest or Smallest | javacpython-change-biggest-or-smallest-b-u67s | Intuition\nChange the biggest or the smallest,\nto be other existing number.\n\n\n# Explanation\nChange two biggest,\nthen the high score is A[n-3] - A[0]\n\nCh | lee215 | NORMAL | 2023-02-18T16:10:18.184352+00:00 | 2023-02-19T02:26:13.385137+00:00 | 2,481 | false | # **Intuition**\nChange the biggest or the smallest,\nto be other existing number.\n<br>\n\n# **Explanation**\nChange two biggest,\nthen the high score is `A[n-3] - A[0]`\n\nChange the biggest and the smallest,\nthen the high score is `A[n-2] - A[1]`\n\nChange two smallest,\nthen the high score is `A[n-1] - A[2]`\n\nFo... | 30 | 2 | ['C', 'Python', 'Java'] | 7 |
minimum-score-by-changing-two-elements | C++ | Python - Short and easy to understand with sorting | c-python-short-and-easy-to-understand-wi-t15m | Intuition\nWe see that we have to sort the array to easily find low score and high score\n\n# Approach\nAfter sorting the array, we have 3 ways to optimize this | nvthang | NORMAL | 2023-02-18T16:04:48.968039+00:00 | 2023-02-19T09:28:18.543827+00:00 | 2,171 | false | # Intuition\nWe see that we have to sort the array to easily find **low** score and **high** score\n\n# Approach\nAfter sorting the array, we have 3 ways to optimize this problem:\n- Increase `nums[0], nums[1] equal to nums[2]`, now `low=0`, `high=nums[n-1]-nums[2]`\n- Reduce `nums[n-1], nums[n-2] equal to nums[n-3]`,... | 24 | 2 | ['C', 'Sorting'] | 4 |
minimum-score-by-changing-two-elements | 3 Step Logic + Video Solution || c++ solution | 3-step-logic-video-solution-c-solution-b-p4q6 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nhttps://youtu.be/pBJgRVQEDPE\n Describe your approach to solving the prob | u-day | NORMAL | 2023-02-18T16:24:49.764940+00:00 | 2023-02-19T02:00:20.809957+00:00 | 772 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nhttps://youtu.be/pBJgRVQEDPE\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add ... | 16 | 0 | ['C++'] | 1 |
minimum-score-by-changing-two-elements | 🔥 [LeetCode The Hard Way] 🔥 Explained Line By Line | leetcode-the-hard-way-explained-line-by-5ccpm | \uD83D\uDD34 Check out LeetCode The Hard Way for more solution explanations and tutorials. \n\uD83D\uDFE0 Check out our Discord Study Group for live discussion. | __wkw__ | NORMAL | 2023-02-18T16:15:53.925192+00:00 | 2023-02-18T16:33:17.430075+00:00 | 789 | false | \uD83D\uDD34 Check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. \n\uD83D\uDFE0 Check out our [Discord Study Group](https://discord.gg/Nqm4jJcyBf) for live discussion.\n\uD83D\uDFE2 Give a star on [Github Repository](https://github.com/wing... | 13 | 2 | ['C', 'Sorting'] | 1 |
minimum-score-by-changing-two-elements | O(n) | on-by-votrubac-cjcg | We can always make the low score zero. Therefore, we should focus on reducing the high score.\n\nFor that, we can either remove two smallest, one smallest and o | votrubac | NORMAL | 2023-02-18T16:00:58.463566+00:00 | 2023-02-18T16:40:50.031102+00:00 | 792 | false | We can always make the low score zero. Therefore, we should focus on reducing the high score.\n\nFor that, we can either remove two smallest, one smallest and one largest, or two largest elements.\n\nWe use partial sort to find two largest and two smallest elements, so that the time complexity is O(n).\n\n**C++**\n```c... | 12 | 1 | ['C'] | 1 |
minimum-score-by-changing-two-elements | Python 3 || 2 lines, w/ explanation || T/S: 72% / 81% | python-3-2-lines-w-explanation-ts-72-81-lh1o6 | \nclass Solution:\n def minimizeSum(self, nums: List[int]) -> int:\n\n nums.sort()\n\n return min(nums[-1] - nums[2], # [a,b,c, ..., x,y,z] = | Spaulding_ | NORMAL | 2023-02-20T05:15:38.459839+00:00 | 2024-06-21T20:14:37.361517+00:00 | 196 | false | ```\nclass Solution:\n def minimizeSum(self, nums: List[int]) -> int:\n\n nums.sort()\n\n return min(nums[-1] - nums[2], # [a,b,c, ..., x,y,z] => [c,c,c, ..., x,y,z]\n nums[-2] - nums[1], # [a,b,c, ..., x,y,z] => [b,b,c, ..., x,y,y] \n nums[-3] - nums[0]) # [a,... | 9 | 0 | ['Python3'] | 1 |
minimum-score-by-changing-two-elements | Sorting + Three cases only | sorting-three-cases-only-by-priyanshu_ch-50cp | Approach\n Sort the array\n There can be three cases: \n \n1) pick first two and make them third Example:-[1,2,8,9,11]\n2) pick last two and m | Priyanshu_Chaudhary_ | NORMAL | 2023-02-18T16:05:11.011022+00:00 | 2023-02-18T16:05:11.011068+00:00 | 1,027 | false | # Approach\n* Sort the array\n* There can be three cases: \n \n1) pick first two and make them third **Example:-[1,2,8,9,11]**\n2) pick last two and make it third last element **Example:- [1,2,3,9,11]**\n3) pick first and last and make them second and second last element **Example:- [1... | 9 | 0 | ['Sorting', 'C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.