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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
two-best-non-overlapping-events | 2 Approaches, loop + Binary Search || Easy to understand || with Explaination | 2-approaches-loop-binary-search-easy-to-ol29y | Intuition\nQuestion asked to select at most 2 events which are not colliding with each other. We can select one in first for loop and try for all other events i | RiteshHajare | NORMAL | 2024-12-08T15:09:18.155062+00:00 | 2024-12-08T15:09:18.155103+00:00 | 63 | false | # Intuition\nQuestion asked to select **at most 2** events which are not colliding with each other. We can select one in first for loop and try for all other events if they collide with current event, if it doesn\'t collide, we can save maximum of all answers, but this will take O(n^2) time which will lead to time limi... | 1 | 0 | ['Binary Search', 'Dynamic Programming', 'Sorting', 'C++'] | 0 |
two-best-non-overlapping-events | ✅ Simple Java Solution | simple-java-solution-by-harsh__005-bxcx | CODE\nJava []\npublic int maxTwoEvents(int[][] events) {\n\tArrays.sort(events, (int a[], int b[])->{\n\t\tif(a[1] == b[1]){\n\t\t\treturn b[2]-a[2];\n\t\t}\n\t | Harsh__005 | NORMAL | 2024-12-08T13:20:00.392938+00:00 | 2024-12-08T13:20:00.392963+00:00 | 111 | false | ## **CODE**\n```Java []\npublic int maxTwoEvents(int[][] events) {\n\tArrays.sort(events, (int a[], int b[])->{\n\t\tif(a[1] == b[1]){\n\t\t\treturn b[2]-a[2];\n\t\t}\n\t\treturn a[1]-b[1];\n\t});\n\tint max = 0;\n\tTreeMap<Integer,Integer> map = new TreeMap<>();\n\tmap.put(0,0);\n\tfor(int[] e:events){\n\t\tint earn =... | 1 | 0 | ['Java'] | 1 |
two-best-non-overlapping-events | Golang Easy solutions | golang-easy-solutions-by-tarunnahak-utqk | \n\n# Code\ngolang []\nimport (\n\t"sort"\n)\n\nfunc maxTwoEvents(events [][]int) int {\n\t// Step 1: Sort events by their end times\n\tsort.Slice(events, func( | Tarunnahak | NORMAL | 2024-12-08T13:13:22.168125+00:00 | 2024-12-08T13:13:22.168168+00:00 | 32 | false | \n\n# Code\n```golang []\nimport (\n\t"sort"\n)\n\nfunc maxTwoEvents(events [][]int) int {\n\t// Step 1: Sort events by their end times\n\tsort.Slice(events, func(i, j int) bool {\n\t\treturn events[i][1] < events[j][1]\n\t})\n\n\tn := len(events)\n\tmaxValues := make([]int, n)\n\tmaxValues[0] = events[0][2] // Value o... | 1 | 0 | ['Go'] | 0 |
two-best-non-overlapping-events | 🏆 Binary Search & Max Value Tracking || ~25ms in Rust & Go || Brief and Clear Description | binary-search-max-value-tracking-25ms-in-wylz | \uD83D\uDE07 Intuition\n\nTo maximize the sum of values from two non-overlapping events, we leverage the sorted order of events by $end\_time$ to efficiently fi | rutsh | NORMAL | 2024-12-08T13:08:37.260737+00:00 | 2024-12-08T13:11:21.073537+00:00 | 21 | false | # \uD83D\uDE07 Intuition\n\nTo maximize the sum of values from two non-overlapping events, we leverage the sorted order of events by $end\\_time$ to efficiently find the best candidate for the second event using binary search. Sorting helps us ensure __efficient lookup__ for compatible events, while a __right-to-left m... | 1 | 0 | ['Array', 'Binary Search', 'Go', 'Rust'] | 0 |
two-best-non-overlapping-events | GO | Binary Search On End Date | go-binary-search-on-end-date-by-2107mohi-bw41 | 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 | 2107mohitverma | NORMAL | 2024-12-08T12:43:43.031277+00:00 | 2024-12-08T12:43:43.031316+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. -->\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 | ['Go'] | 0 |
two-best-non-overlapping-events | Easy simple intutive solution 💯🧠⚡ || C++ | easy-simple-intutive-solution-c-by-srimu-p2q3 | Approach\n Describe your approach to solving the problem. \nFirst sort the events based on their start time and then store the sorted start times in a seperate | srimukheshsuru | NORMAL | 2024-12-08T12:13:09.483033+00:00 | 2024-12-08T12:13:09.483064+00:00 | 113 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nFirst sort the events based on their start time and then store the sorted start times in a seperate array where you can do a binary search on. Then create a suffix array which $$i^\\text{th}$$ value stores the maximum value whose start time is greater... | 1 | 0 | ['Array', 'Binary Search', 'Dynamic Programming', 'Sorting', 'C++'] | 1 |
two-best-non-overlapping-events | Kotlin | Rust | kotlin-rust-by-samoylenkodmitry-r8wr | \n\nhttps://youtu.be/uBoGo4P9t9E\n\n#### Join me on Telegram\n\nhttps://t.me/leetcode_daily_unstoppable/826\n\n#### Problem TLDR\n\nMax two non-overlapping inte | SamoylenkoDmitry | NORMAL | 2024-12-08T10:11:10.590244+00:00 | 2024-12-08T10:11:23.413669+00:00 | 40 | false | \n\nhttps://youtu.be/uBoGo4P9t9E\n\n#### Join me on Telegram\n\nhttps://t.me/leetcode_daily_unstoppable/826\n\n#### Problem TLDR\n\nMax two non-overlapping intervals #medium #binary_search\n\n#### Intuition\n... | 1 | 0 | ['Binary Search', 'Line Sweep', 'Heap (Priority Queue)', 'C++', 'Rust', 'Kotlin'] | 0 |
two-best-non-overlapping-events | Easy Explanation for Binary Search || C++ | easy-explanation-for-binary-search-c-by-5rbdd | Intuition\nFind the maximum Value of two non-overlapping events\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. We know that if | sachin_rayal | NORMAL | 2024-12-08T10:11:04.421749+00:00 | 2024-12-08T10:11:04.421771+00:00 | 8 | false | # Intuition\nFind the **maximum Value** of two non-overlapping events\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. We know that if `event i` end before `event j`, then every `event n` that ended before `event i-1` is also ended.\n2. For that we sort the `events` on the bases of... | 1 | 0 | ['Binary Search', 'C++'] | 0 |
two-best-non-overlapping-events | [Kotlin] Two sorts - simple and short | kotlin-two-sorts-simple-and-short-by-sil-9vlu | Approach\nUse two sorted arrays - one by end time, the other by by value (highest first).\n\nThen, we iterate through the events sorted by end time. We keep an | silyevsk | NORMAL | 2024-12-08T09:28:21.306658+00:00 | 2024-12-08T09:28:21.306685+00:00 | 12 | false | # Approach\nUse two sorted arrays - one by end time, the other by by value (highest first).\n\nThen, we iterate through the events sorted by end time. We keep an index pointing to the current element in the events sorted by value, advancing it to the highest possible event not overlapping with the events iterated over ... | 1 | 0 | ['Kotlin'] | 0 |
two-best-non-overlapping-events | Sorting two times - view data in the different ways | sorting-two-times-view-data-in-the-diffe-ep94 | Intuition\nTo maximize the selection of two non-overlapping events, we can sort the events in two different ways:\n- Sort by Increasing End Time: This allows us | luudanhhieu | NORMAL | 2024-12-08T08:13:57.324304+00:00 | 2024-12-08T08:13:57.324328+00:00 | 19 | false | # Intuition\nTo maximize the selection of two non-overlapping events, we can sort the events in two different ways:\n- Sort by Increasing End Time: This allows us to find the maximum value for a specific end time.\n- Sort by Decreasing Start Time: This helps us determine the maximum value for a specific start time.\nBy... | 1 | 0 | ['Go'] | 0 |
two-best-non-overlapping-events | Easy C++ Solution ⭐||Explanation✔|| Beats 93.24%🎯|| PLEASE UPVOTE ⬆ | easy-c-solution-explanation-beats-9324-p-6dam | Intuition\n Describe your first thoughts on how to solve this problem. \nThe goal is to maximize the sum of values by attending at most two non-overlapping even | Abhijithsr13 | NORMAL | 2024-12-08T08:04:31.763542+00:00 | 2024-12-08T08:04:31.763573+00:00 | 15 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe goal is to maximize the sum of values by attending at most two non-overlapping events. The problem boils down to efficiently finding the best combination of two events where one event ends before the other starts. Sorting the events b... | 1 | 0 | ['Array', 'Binary Search', 'Dynamic Programming', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 0 |
sort-array-by-increasing-frequency | Python 3 solution - with process of thinking and improvement | python-3-solution-with-process-of-thinki-7ruf | Part 1\n\nSunday morning, Spotify, coffee, console... Task from the list of tasks to solve later.\nLet\'s go!\n\npython\n~ \u276F python3 | denisrasulev | NORMAL | 2021-02-14T12:14:17.303649+00:00 | 2021-02-14T12:15:52.403446+00:00 | 19,938 | false | # Part 1\n\nSunday morning, Spotify, coffee, console... Task from the list of tasks to solve later.\nLet\'s go!\n\n```python\n~ \u276F python3 at 10:38:03\nPython 3.9.1 (default, Feb 3 2021, 07:38:02)\n[... | 341 | 2 | ['Python', 'Python3'] | 28 |
sort-array-by-increasing-frequency | [Java] Simple Custom Sort with Detailed Explanation! | java-simple-custom-sort-with-detailed-ex-rq4k | \npublic int[] frequencySort(int[] nums) {\n\tMap<Integer, Integer> map = new HashMap<>();\n\t// count frequency of each number\n\tArrays.stream(nums).forEach(n | jerrywusa | NORMAL | 2020-10-31T18:43:01.623568+00:00 | 2020-10-31T18:48:41.240761+00:00 | 25,902 | false | ```\npublic int[] frequencySort(int[] nums) {\n\tMap<Integer, Integer> map = new HashMap<>();\n\t// count frequency of each number\n\tArrays.stream(nums).forEach(n -> map.put(n, map.getOrDefault(n, 0) + 1));\n\t// custom sort\n\treturn Arrays.stream(nums).boxed()\n\t\t\t.sorted((a,b) -> map.get(a) != map.get(b) ? map.g... | 205 | 9 | ['Sorting', 'Java'] | 22 |
sort-array-by-increasing-frequency | ✅💯🔥Explanations No One Will Give You🎓🧠Very Detailed Approach🎯🔥Extremely Simple And Effective🔥 | explanations-no-one-will-give-youvery-de-nksb | \n \n \n Never limit yourself because of others\u2019 limited imagination; never limit others because of your own limited imagi | heir-of-god | NORMAL | 2024-07-23T04:44:04.758338+00:00 | 2024-07-23T04:44:04.758366+00:00 | 32,794 | false | <blockquote>\n <p>\n <b>\n Never limit yourself because of others\u2019 limited imagination; never limit others because of your own limited imagination\n </b> \n </p>\n <p>\n --- Mae Jemison ---\n </p>\n</blockquote>\n\n# \uD83D\uDC51Pro... | 164 | 28 | ['Array', 'Hash Table', 'C', 'Sorting', 'Counting Sort', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 15 |
sort-array-by-increasing-frequency | [C++/Python] Sort | cpython-sort-by-lee215-wqi6 | Explanation\nSort by 2 keys.\n@v_paliy note that:\n"count[x] sorts by frequency, and if two values are equal, it will sort the keys in decreasing order."\n\n\n# | lee215 | NORMAL | 2020-10-31T16:16:55.155677+00:00 | 2020-11-01T14:14:19.689679+00:00 | 24,407 | false | ## **Explanation**\nSort by 2 keys.\n@v_paliy note that:\n"count[x] sorts by frequency, and if two values are equal, it will sort the keys in decreasing order."\n<br>\n\n## **Complexity**\nTime `O(NlogN)`\nSpace `O(N)`\n<br>\n\n**C++**\n```cpp\n vector<int> frequencySort(vector<int>& A) {\n unordered_map<int,... | 147 | 4 | [] | 31 |
sort-array-by-increasing-frequency | 1-liner|count freq[x+100] & sort by lambda vs Counting sort||0ms beats 100% | 1-linercount-freqx100-sort-by-lambda-vs-t99lk | Intuition\n Describe your first thoughts on how to solve this problem. \nSince the constraints -100 <= nums[i] <= 100 count freq[x+100] for x in nums\nThen sort | anwendeng | NORMAL | 2024-07-23T00:30:23.702684+00:00 | 2024-07-23T23:55:39.377272+00:00 | 17,557 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSince the constraints `-100 <= nums[i] <= 100` count freq[x+100] for x in nums\nThen sort it by a lambda which is fast both in C++& Python. Similar concept, using Counter in python, a 1-liner is given, the 1st version for that is slow but... | 60 | 2 | ['Array', 'Hash Table', 'Sorting', 'Counting Sort', 'C++', 'Python3'] | 20 |
sort-array-by-increasing-frequency | Python solution | python-solution-by-a_bs-8gir | Code\n\nfrom collections import Counter\n\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n freq = Counter(nums)\n nu | 20250406.A_BS | NORMAL | 2024-07-23T02:43:49.796604+00:00 | 2024-07-23T02:43:49.796640+00:00 | 5,095 | false | # Code\n```\nfrom collections import Counter\n\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n freq = Counter(nums)\n nums.sort(key=lambda x: (freq[x], -x))\n return nums\n\n```\n### Example 1\n**Input:** `nums = [1, 1, 2, 2, 2, 3]`\n\n**Step 1: Count the frequency of... | 57 | 0 | ['Python3'] | 12 |
sort-array-by-increasing-frequency | C++ solution using maps | c-solution-using-maps-by-aparna_g-7kzn | This is question is a very slight modifictaion of https://leetcode.com/problems/sort-characters-by-frequency/\nThis is just a basic implementation :-)\n\nclass | aparna_g | NORMAL | 2021-04-07T06:42:11.777280+00:00 | 2021-04-07T07:00:17.458777+00:00 | 12,415 | false | This is question is a very slight modifictaion of https://leetcode.com/problems/sort-characters-by-frequency/\nThis is just a basic implementation :-)\n```\nclass Solution {\npublic:\n \n static bool cmp(pair<int,int>&a, pair<int,int>&b) {\n return (a.second==b.second) ? a.first>b.first : a.second<b.secon... | 52 | 1 | ['C', 'Sorting', 'C++'] | 8 |
sort-array-by-increasing-frequency | [Java] Sorted the Occurrence by Using Collections.sort().. | java-sorted-the-occurrence-by-using-coll-yfn2 | Looks like there is no others using this in Java at this moment yet, so I post my solution here for your reference.\n\n public int[] frequencySort(int[] nums | admin007 | NORMAL | 2020-10-31T16:36:25.024103+00:00 | 2020-11-02T20:16:09.290355+00:00 | 8,663 | false | Looks like there is no others using this in Java at this moment yet, so I post my solution here for your reference.\n```\n public int[] frequencySort(int[] nums) {\n Map<Integer, Integer> map = new HashMap<>();\n for (int num : nums) {\n map.put(num, map.getOrDefault(num, 0) + 1);\n }... | 49 | 2 | [] | 9 |
sort-array-by-increasing-frequency | Easy Solution by using map || Using inbuilt sorting technique 😎 || Solution in C++ and Java 💯✅ | easy-solution-by-using-map-using-inbuilt-umna | Screenshot \uD83D\uDCC3\n\n\n\n# Intuition \uD83E\uDD14\n Describe your first thoughts on how to solve this problem. \nWe need to keep the track of numbers in n | purnimakesarwani47 | NORMAL | 2024-07-23T00:21:20.241547+00:00 | 2024-07-23T00:21:20.241576+00:00 | 14,085 | false | # Screenshot \uD83D\uDCC3\n\n\n\n# Intuition \uD83E\uDD14\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to keep the track of numbers in nums that how many times it has been o... | 48 | 0 | ['Array', 'Hash Table', 'Sorting', 'C++', 'Java'] | 8 |
sort-array-by-increasing-frequency | Java HashMap Collections.sort() easy to understand | java-hashmap-collectionssort-easy-to-und-xcrr | \nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer, Integer> map = new HashMap<>();\n for (int num : nums) {\n | coolmike | NORMAL | 2021-01-24T18:14:13.488713+00:00 | 2021-01-24T18:14:13.488744+00:00 | 8,184 | false | ```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer, Integer> map = new HashMap<>();\n for (int num : nums) {\n map.put(num, map.getOrDefault(num, 0) + 1);\n }\n \n List<Integer> list = new ArrayList<>(map.keySet());\n Collections.sort(l... | 44 | 4 | ['Java'] | 9 |
sort-array-by-increasing-frequency | 1636. Sort Array by Increasing Frequency Javascript solution | 1636-sort-array-by-increasing-frequency-5c50d | \n\nvar frequencySort = function(nums) {\n const map = new Map();\n for (let n of nums) {\n map.set(n, (map.get(n) + 1) || 1);\n }\n return n | kondaldurgam | NORMAL | 2020-10-31T16:39:07.751635+00:00 | 2020-10-31T16:39:07.751670+00:00 | 3,610 | false | ```\n\nvar frequencySort = function(nums) {\n const map = new Map();\n for (let n of nums) {\n map.set(n, (map.get(n) + 1) || 1);\n }\n return nums.sort((a, b) => map.get(a) - map.get(b) || b - a)\n};\n``` | 43 | 0 | ['JavaScript'] | 3 |
sort-array-by-increasing-frequency | C++/Python3 Sort by Count | cpython3-sort-by-count-by-votrubac-7rrk | C++\nSince the range of numbers is limited, and I am using array to collect count for the performance.\ncpp\nvector<int> frequencySort(vector<int>& nums) {\n | votrubac | NORMAL | 2020-10-31T16:00:44.916506+00:00 | 2020-10-31T17:22:53.899994+00:00 | 10,054 | false | **C++**\nSince the range of numbers is limited, and I am using array to collect count for the performance.\n```cpp\nvector<int> frequencySort(vector<int>& nums) {\n int cnt[201] = {};\n for (auto n : nums)\n ++cnt[n + 100];\n sort(begin(nums), end(nums), [&](int a, int b) {\n return cnt[a + 100] =... | 43 | 6 | [] | 7 |
sort-array-by-increasing-frequency | JAVA | HashMap | Sorting | Explained | java-hashmap-sorting-explained-by-sourin-xgd1 | Please Upvote :D\n---\n- We create a frequency map as well as an arraylist to store the values in nums so that we can custom sort it.\n\n- We then sort the lis | sourin_bruh | NORMAL | 2022-09-25T12:13:56.617751+00:00 | 2023-01-07T07:17:35.464999+00:00 | 10,254 | false | # Please Upvote :D\n---\n- We create a frequency map as well as an arraylist to store the values in nums so that we can custom sort it.\n\n- We then sort the list in increasing order of map values (i.e. the frequency of nums elements).\n\n- If two or more values (frequencies) happens to be same, then we sort the eleme... | 39 | 0 | ['Hash Table', 'Sorting', 'Java'] | 8 |
sort-array-by-increasing-frequency | Easy Python Solution with Explanation | easy-python-solution-with-explanation-by-2sjl | \tfrom collections import Counter\n\tclass Solution:\n\t\tdef frequencySort(self, nums: List[int]) -> List[int]:\n\t\t\td = Counter(nums)\n\t\t\tdef check(x):\n | shadow_sm36 | NORMAL | 2020-11-01T07:42:57.495338+00:00 | 2020-11-01T07:51:26.888058+00:00 | 5,756 | false | \tfrom collections import Counter\n\tclass Solution:\n\t\tdef frequencySort(self, nums: List[int]) -> List[int]:\n\t\t\td = Counter(nums)\n\t\t\tdef check(x):\n\t\t\t\treturn d[x]\n\n\t\t\tnums.sort(reverse=True)\n\t\t\tnums.sort(key=check)\n\t\t\treturn nums\n\t\t\t\nSo the basic idea is we use the Python\'s inbuilt s... | 36 | 2 | ['Sorting', 'Python', 'Python3'] | 5 |
sort-array-by-increasing-frequency | C++| 100% faster| EASY TO UNDERSTAND | fast and efficient code using comparator function | c-100-faster-easy-to-understand-fast-and-33f9 | Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome\n```\nclass | aarindey | NORMAL | 2021-06-17T20:19:07.565333+00:00 | 2021-06-17T20:19:07.565365+00:00 | 3,984 | false | ***Please upvote to motivate me in my quest of documenting all leetcode solutions. HAPPY CODING:)\nAny suggestions and improvements are always welcome***\n```\nclass Solution {\npublic:\n bool static comp(pair<int,int> a,pair<int,int> b)\n {\n if(a.second==b.second)\n return a>b; \n else\n ... | 35 | 2 | ['C'] | 3 |
sort-array-by-increasing-frequency | [java/Python 3] Sort frequency followed by value. | javapython-3-sort-frequency-followed-by-n69hh | \njava\n public int[] frequencySort(int[] nums) {\n var freq = new HashMap<Integer, Integer>();\n for (int n : nums) {\n freq.put(n, | rock | NORMAL | 2020-10-31T16:31:10.346370+00:00 | 2020-11-22T17:44:26.289102+00:00 | 5,442 | false | \n```java\n public int[] frequencySort(int[] nums) {\n var freq = new HashMap<Integer, Integer>();\n for (int n : nums) {\n freq.put(n, 1 + freq.getOrDefault(n, 0));\n }\n var pq = new PriorityQueue<Integer>(Comparator.<Integer, Integer>comparing(i -> freq.get(i)).thenComparing... | 28 | 2 | [] | 11 |
sort-array-by-increasing-frequency | Python 1-liner | python-1-liner-by-lokeshsk1-34mk | \nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n return sorted(sorted(nums,reverse=1),key=nums.count)\n | lokeshsk1 | NORMAL | 2020-12-07T12:33:51.755506+00:00 | 2020-12-07T12:34:04.970476+00:00 | 2,627 | false | ```\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n return sorted(sorted(nums,reverse=1),key=nums.count)\n``` | 26 | 2 | ['Python', 'Python3'] | 9 |
sort-array-by-increasing-frequency | Simple C++ Solution | simple-c-solution-by-arbind007-hmuq | \nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map <int,int> mp;\n priority_queue <pair <int,int>> q; | Arbind007 | NORMAL | 2022-02-02T07:40:28.181622+00:00 | 2022-10-09T06:19:07.762082+00:00 | 5,661 | false | ```\nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map <int,int> mp;\n priority_queue <pair <int,int>> q;\n for(int i=0;i<nums.size();i++){\n mp[nums[i]]++;\n }\n for(auto &i:mp){\n q.push({-i.second,i.first});\n ... | 24 | 0 | ['Array', 'Hash Table', 'Sorting', 'Heap (Priority Queue)', 'C++'] | 2 |
sort-array-by-increasing-frequency | [c++] || Sort Array by Increasing Frequency | c-sort-array-by-increasing-frequency-by-m6dyr | \nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n map<int,int> mp;\n for(int i=0;i<nums.size();i++){\n | durgirajesh_ | NORMAL | 2021-09-20T05:47:09.411899+00:00 | 2021-09-20T05:47:09.411949+00:00 | 3,275 | false | ```\nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n map<int,int> mp;\n for(int i=0;i<nums.size();i++){\n mp[nums[i]]++;\n }\n priority_queue<pair<int,int>> pq;\n for(auto it : mp){\n pq.push({-it.second,it.first});\n }\n ... | 24 | 0 | ['C', 'Heap (Priority Queue)'] | 4 |
sort-array-by-increasing-frequency | Simple Python solution with explanation | simple-python-solution-with-explanation-gwu28 | We are going to use a dictionary to keep track of the frequeny that a number appears in the array. After we have done that we first sort the array in decreasing | stevenbooke | NORMAL | 2021-02-21T01:11:35.394801+00:00 | 2021-02-21T01:11:35.394827+00:00 | 2,013 | false | We are going to use a dictionary to keep track of the frequeny that a number appears in the array. After we have done that we first sort the array in decreasing order and then sort it in increasing order by frequency. This works because sorts are guarenteed to be stable. Read this if you need help understanding why thi... | 20 | 2 | ['Python'] | 3 |
sort-array-by-increasing-frequency | Easiest one line solution in python | easiest-one-line-solution-in-python-by-m-ttii | 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 | Mohammad_tanveer | NORMAL | 2023-03-04T20:05:12.251357+00:00 | 2023-03-04T20:05:12.251391+00:00 | 1,657 | 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)$$ --... | 17 | 0 | ['Python3'] | 0 |
sort-array-by-increasing-frequency | ✅Easiest 3 Step Cpp / Java / Py / JS Solution | Two Approaches 🏆| Map+Heap | easiest-3-step-cpp-java-py-js-solution-t-ohnn | Explanation Heap\n##### Step 1: Count Frequencies\nWe use an unordered map freq_map to count the frequency of each number.\n##### Step 2:Heap (Priority Queue):\ | dev_yash_ | NORMAL | 2024-07-23T01:50:09.860454+00:00 | 2024-07-23T01:50:09.860488+00:00 | 4,017 | false | ### **Explanation Heap**\n##### **Step 1: Count Frequencies**\nWe use an unordered map freq_map to count the frequency of each number.\n##### **Step 2:Heap (Priority Queue):**\n* We use a max-heap (priority queue) to store the numbers in such a way that they are ordered by their frequency and value.\n* The custom compa... | 16 | 0 | ['Array', 'Hash Table', 'C', 'Sorting', 'Heap (Priority Queue)', 'Python', 'Python3', 'JavaScript'] | 6 |
sort-array-by-increasing-frequency | EASY C++ SOLUTION | HEAPS | MAPS | easy-c-solution-heaps-maps-by-theadeshkh-5czb | \nvector<int> frequencySort(vector<int>& nums) {\n unordered_map<int, int> m;\n unordered_map<int, int>::iterator it;\n priority_queue<pair | theadeshkhanna | NORMAL | 2022-05-08T19:40:52.233051+00:00 | 2022-05-08T19:40:52.233081+00:00 | 2,829 | false | ```\nvector<int> frequencySort(vector<int>& nums) {\n unordered_map<int, int> m;\n unordered_map<int, int>::iterator it;\n priority_queue<pair<int, int>> pq;\n \n vector<int> v;\n int n = nums.size();\n \n for (int i = 0; i < n; i++) {\n m[nums[i]]++;\n... | 14 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 3 |
sort-array-by-increasing-frequency | Python one line solution | python-one-line-solution-by-tovam-rdcs | Python :\n\n\ndef frequencySort(self, nums: List[int]) -> List[int]:\n\treturn sorted(sorted(nums, reverse=True), key=nums.count)\n\n\nLike it ? please upvote ! | TovAm | NORMAL | 2021-10-25T21:21:08.655222+00:00 | 2021-10-25T21:21:08.655252+00:00 | 1,321 | false | **Python :**\n\n```\ndef frequencySort(self, nums: List[int]) -> List[int]:\n\treturn sorted(sorted(nums, reverse=True), key=nums.count)\n```\n\n**Like it ? please upvote !** | 14 | 1 | ['Python', 'Python3'] | 1 |
sort-array-by-increasing-frequency | Easy to Understand Python Solution | easy-to-understand-python-solution-by-ay-ll69 | \nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n nums.sort(reverse=True)\n\n res = sorted(nums, key=nums.count)\n | ayushi7rawat | NORMAL | 2021-05-06T04:31:39.766692+00:00 | 2021-05-06T04:31:39.766733+00:00 | 1,201 | false | ```\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n nums.sort(reverse=True)\n\n res = sorted(nums, key=nums.count)\n return res\n``` | 14 | 2 | ['Python'] | 2 |
sort-array-by-increasing-frequency | C++ || Hashmap || Simple + Optimized | c-hashmap-simple-optimized-by-meurudesu-vchr | \n# Code\n\nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map<int, int> mp;\n for(auto i : nums) { // | meurudesu | NORMAL | 2024-02-07T10:56:49.885634+00:00 | 2024-02-07T10:56:49.885667+00:00 | 1,698 | false | \n# Code\n```\nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map<int, int> mp;\n for(auto i : nums) { // store cnt of every num\n mp[i]++;\n }\n sort(nums.begin(), nums.end(), [&](int a, int b) {\n if(mp[a] == mp[b]) return a ... | 13 | 0 | ['Hash Table', 'C++'] | 4 |
sort-array-by-increasing-frequency | Java Easy to understand using Comparator class | java-easy-to-understand-using-comparator-xew3 | \nclass Solution {\n HashMap<Integer, Integer> map = new HashMap<>();\n \n class Sorter implements Comparator<Integer>{\n\t//comparing the frequencies | harshu175 | NORMAL | 2021-04-23T21:14:08.218211+00:00 | 2021-04-23T21:14:08.218255+00:00 | 2,149 | false | ```\nclass Solution {\n HashMap<Integer, Integer> map = new HashMap<>();\n \n class Sorter implements Comparator<Integer>{\n\t//comparing the frequencies \n public int compare(Integer a, Integer b){\n if(map.get(a) == map.get(b)){\n return b-a;\n }else{\n ... | 13 | 1 | ['Array', 'Java'] | 1 |
sort-array-by-increasing-frequency | C++ Sort by frequency | c-sort-by-frequency-by-lzl124631x-7ytw | See my latest update in repo LeetCode\n\n## Solution 1. Sort\n\ncpp\n// OJ: https://leetcode.com/contest/biweekly-contest-38/problems/sort-array-by-increasing-f | lzl124631x | NORMAL | 2020-10-31T16:02:48.992134+00:00 | 2020-11-01T20:11:03.307707+00:00 | 2,896 | false | See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Sort\n\n```cpp\n// OJ: https://leetcode.com/contest/biweekly-contest-38/problems/sort-array-by-increasing-frequency/\n// Author: github.com/lzl124631x\n// Time: O(NlogN)\n// Space: O(N)\nclass Solution {\npublic:\n vect... | 13 | 1 | [] | 4 |
sort-array-by-increasing-frequency | Java Easy Solution || Sort Method | java-easy-solution-sort-method-by-aanand-xx4h | ```\npublic int[] frequencySort(int[] nums) {\n Map map=new HashMap<>();//map to store count of each number\n List list=new ArrayList<>();\n | aanandsj1706 | NORMAL | 2020-10-31T16:02:09.924780+00:00 | 2020-10-31T16:06:42.982881+00:00 | 3,604 | false | ```\npublic int[] frequencySort(int[] nums) {\n Map<Integer,Integer> map=new HashMap<>();//map to store count of each number\n List<Integer> list=new ArrayList<>();\n for(int num:nums){\n if(map.containsKey(num))\n map.put(num,map.get(num)+1);\n else{\n ... | 13 | 1 | [] | 6 |
sort-array-by-increasing-frequency | Javascript sort | javascript-sort-by-fbecker11-59dn | \nvar frequencySort = function(nums) {\n const map = new Map()\n for(let n of nums){\n map.set(n, (map.get(n) || 0)+1)\n }\n return nums.sort((a,b)=>{\n | fbecker11 | NORMAL | 2020-11-25T14:47:48.460247+00:00 | 2020-11-25T14:47:48.460277+00:00 | 1,714 | false | ```\nvar frequencySort = function(nums) {\n const map = new Map()\n for(let n of nums){\n map.set(n, (map.get(n) || 0)+1)\n }\n return nums.sort((a,b)=>{\n if(map.get(a) === map.get(b)){\n return b-a\n }else{\n return map.get(a) - map.get(b)\n }\n })\n};\n``` | 12 | 0 | ['Sorting', 'JavaScript'] | 3 |
sort-array-by-increasing-frequency | Sort Array by Increasing Frequency [ C++] 96% faster solution | sort-array-by-increasing-frequency-c-96-zj5ek | Intuition\n Describe your first thoughts on how to solve this problem. \nFirsly as we see frequecy the intuition is to use map. We store the freq in map and the | shreyajain1808 | NORMAL | 2023-06-01T18:01:24.593120+00:00 | 2023-06-01T18:01:24.593159+00:00 | 2,296 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirsly as we see frequecy the intuition is to use map. We store the freq in map and then think of how to use heap for sorting.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMap stores te frequency of each element... | 11 | 1 | ['C++'] | 0 |
sort-array-by-increasing-frequency | Java SIMPLE solution using TreeMap and with explanation faster than 100.00% | java-simple-solution-using-treemap-and-w-zgxx | \nclass Solution {\n public int[] frequencySort(int[] nums) {\n int[] bucket = new int[201]; //An array bucket to store frequency of numbers ranged be | sandip_chanda | NORMAL | 2020-10-31T17:40:22.012854+00:00 | 2020-10-31T18:13:20.359751+00:00 | 2,403 | false | ```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n int[] bucket = new int[201]; //An array bucket to store frequency of numbers ranged between -100 to 100\n for(int num : nums) {\n bucket[num+100]++;\n }\n TreeMap<Integer, List<Integer>> map = new TreeMap(); //T... | 11 | 0 | ['Java'] | 2 |
sort-array-by-increasing-frequency | Very Easy approach | Simple map + sorting | Vid explantion | very-easy-approach-simple-map-sorting-vi-q6db | Vid Explanation\nhttps://youtu.be/Ys7eYFNzgEI\n# Intuition\n Describe your first thoughts on how to solve this problem. \nThe natural intuition for this problem | Atharav_s | NORMAL | 2024-07-23T01:55:23.624670+00:00 | 2024-07-23T01:55:23.624687+00:00 | 3,243 | false | # Vid Explanation\nhttps://youtu.be/Ys7eYFNzgEI\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe natural intuition for this problem is to first count the occurrences of each number in the array. This gives us a mapping between numbers and their frequencies. Then, we can sort the nu... | 10 | 0 | ['C++'] | 0 |
sort-array-by-increasing-frequency | Java || Easy Approach with Explanation || HashMap || Heap( min + max ) | java-easy-approach-with-explanation-hash-k5ib | \nclass Solution \n{//T-> O( N log N ) S->O( N )\n public int[] frequencySort(int[] nums)\n {\n Map<Integer, Integer> map= new HashMap<>();//data - | swapnilGhosh | NORMAL | 2021-08-03T09:30:19.006868+00:00 | 2021-08-03T09:37:28.470607+00:00 | 1,836 | false | ```\nclass Solution \n{//T-> O( N log N ) S->O( N )\n public int[] frequencySort(int[] nums)\n {\n Map<Integer, Integer> map= new HashMap<>();//data -- frequency\n \n for(int data: nums)//calculating and putting the frequency of data \n map.put(data, map.getOrDefault(data, 0)+1);\n... | 10 | 0 | ['Heap (Priority Queue)', 'Java'] | 0 |
sort-array-by-increasing-frequency | Just Counting | C++ In-Place Sorting 0 ms 100% | Python3 One-Liners 38 ms 98% | just-counting-c-in-place-sorting-0-ms-10-og09 | Intuition\nThe task is to sort the input array by the element frequencies, ascending. Two elements with the same frequencies should be arranged in descending or | sergei99 | NORMAL | 2024-07-23T09:28:59.473545+00:00 | 2024-10-22T01:12:32.288260+00:00 | 2,963 | false | # Intuition\nThe task is to sort the input array by the element frequencies, ascending. Two elements with the same frequencies should be arranged in descending order by their value. There could be up to $100$ elements in the range $[-100, 100]$.\n\n# Approach\n\n## C++\n\nFor fast enough languages we just introduce an ... | 9 | 0 | ['Array', 'Bit Manipulation', 'Sorting', 'Counting', 'C++', 'Java', 'Python3'] | 1 |
sort-array-by-increasing-frequency | Python 3 || 3 lines, Counter, sort, chain || T/S: 87% / 77% | python-3-3-lines-counter-sort-chain-ts-8-biji | \nLet\'s use an example trace to explain the code.\n\nSuppose that nums = [1,2,1,3,2,3,2].\n\n1. First line trace:\n\nctr = Counter([1,2,1,3,2,3,2]).items()\n | Spaulding_ | NORMAL | 2024-07-23T00:52:57.018434+00:00 | 2024-07-25T16:44:25.575503+00:00 | 721 | false | \nLet\'s use an example trace to explain the code.\n\nSuppose that `nums = [1,2,1,3,2,3,2]`.\n\n1. *First line trace*:\n```\nctr = Counter([1,2,1,3,2,3,2]).items()\n = [(1,2), (2,3), (3,2)]\n```\n2. *Second line trace*:\n```\narr = sorted([(1,2), (2,3), (3,2)], key = lambda x: (x[1], -x[0]))\n = [(3,2), (1,2), (2... | 9 | 0 | ['Python', 'Python3'] | 0 |
sort-array-by-increasing-frequency | One Line Code Python | one-line-code-python-by-ganjinaveen-8s6g | 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 | GANJINAVEEN | NORMAL | 2023-03-04T21:57:54.420282+00:00 | 2023-03-04T21:57:54.420308+00:00 | 1,038 | 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)$$ --... | 9 | 0 | ['Python3'] | 0 |
sort-array-by-increasing-frequency | 0ms !!!! Lowest Complexity and Easy to Understand | 0ms-lowest-complexity-and-easy-to-unders-9mli | 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 | parshanth2005 | NORMAL | 2024-07-23T07:49:41.941859+00:00 | 2024-07-23T07:49:41.941897+00:00 | 1,724 | 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)$$ --... | 8 | 0 | ['Java'] | 6 |
sort-array-by-increasing-frequency | Sort Array by Increasing Frequency | sort-array-by-increasing-frequency-by-ma-xfor | Approach\nStep 1: Counting Frequencies\n\nPurpose: This step counts the frequency of each element in the nums array using a HashMap. The key of the map is the e | MananJain13 | NORMAL | 2024-07-23T04:58:00.828503+00:00 | 2024-07-23T04:58:00.828525+00:00 | 1,912 | false | # Approach\nStep 1: Counting Frequencies\n\nPurpose: This step counts the frequency of each element in the nums array using a HashMap. The key of the map is the element itself, and the value is the frequency of that element.\n\nExplanation:\nLoop through each element in the nums array.\nIf the element is already presen... | 8 | 0 | ['Java'] | 3 |
sort-array-by-increasing-frequency | Best Solution with proper explanation. Beats 100% and 0ms. Trust:) | best-solution-with-proper-explanation-be-51rj | Intuition\n Describe your first thoughts on how to solve this problem. \nFirst map a map, then sort the nums array acoording to the values in the map\n# Approac | sehaj_s5 | NORMAL | 2024-07-23T04:22:19.229625+00:00 | 2024-07-23T04:22:19.229657+00:00 | 773 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst map a map, then sort the nums array acoording to the values in the map\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- make a map, iterate through the nums array and store the frequencies in the map\n- sort t... | 8 | 0 | ['Array', 'Hash Table', 'Sorting', 'C++', 'Go'] | 1 |
sort-array-by-increasing-frequency | Hash Table with Custom Compare Function | C++, Python, Java | hash-table-with-custom-compare-function-j3khg | Approach\n Describe your approach to solving the problem. \nWe can use a hashmap (or an array) freq to map each value in nums to their frequencies, then use a c | not_yl3 | NORMAL | 2024-07-23T00:17:54.859465+00:00 | 2024-07-23T22:47:01.241736+00:00 | 5,849 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nWe can use a hashmap (or an array) `freq` to map each value in `nums` to their frequencies, then use a custom compare function to sort them based on their frequencies. For the custom compare function we must remember that if two numbers have the same ... | 8 | 0 | ['Array', 'Hash Table', 'C', 'Sorting', 'Python', 'C++', 'Java', 'Python3'] | 9 |
sort-array-by-increasing-frequency | java easy to understand solution | java-easy-to-understand-solution-by-aksh-txxy | -> The idea is to use hashmap for storing frequency of the values and then iterate over hashmap and store values and their frequency in 2d array then sort the 2 | Akshat_Mathur | NORMAL | 2022-01-26T12:33:00.741506+00:00 | 2024-07-07T09:28:31.739155+00:00 | 1,649 | false | -> The idea is to use hashmap for storing frequency of the values and then iterate over hashmap and store values and their frequency in 2d array then sort the 2d array on the basis of two columns and then fill the new ans[] array and return it.\n-> We will sort the array on the basis of two columns because values havin... | 8 | 2 | ['Array', 'Hash Table', 'Sorting', 'Java'] | 2 |
sort-array-by-increasing-frequency | ✅ Java - Simple HashMap & PriorityQueue Solution | java-simple-hashmap-priorityqueue-soluti-nw71 | \nclass Solution {\n public int[] frequencySort(int[] nums) {\n //init hashmap and count occurences of elements in nums\n //init minHeap based | welcomecurry | NORMAL | 2021-04-03T03:57:21.487893+00:00 | 2021-04-05T04:08:50.859234+00:00 | 1,756 | false | ```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n //init hashmap and count occurences of elements in nums\n //init minHeap based on occurence, if two elements have same freq sort in decreasing order\n //add elements in map into minHeap as array, containing element and occurence\... | 8 | 0 | ['Heap (Priority Queue)', 'Java'] | 3 |
sort-array-by-increasing-frequency | C++ simple and short with custom comparator lambda function | c-simple-and-short-with-custom-comparato-7kh6 | \nvector<int> frequencySort(vector<int>& nums) {\n\tmap<int, int> freq;\n\tfor (int n : nums)\n\t\tfreq[n]++;\n\tsort(nums.begin(), nums.end(),\n\t\t\t[&freq](c | oleksam | NORMAL | 2020-12-06T11:34:32.194649+00:00 | 2020-12-06T17:54:20.509141+00:00 | 1,721 | false | ```\nvector<int> frequencySort(vector<int>& nums) {\n\tmap<int, int> freq;\n\tfor (int n : nums)\n\t\tfreq[n]++;\n\tsort(nums.begin(), nums.end(),\n\t\t\t[&freq](const int& a, const int& b) {\n\t\t\t\treturn (freq[a] == freq[b]) ? a > b : freq[a] < freq[b];\n\t});\n\treturn nums;\n}\n```\n | 8 | 0 | ['C', 'C++'] | 2 |
sort-array-by-increasing-frequency | HashMap Solution | hashmap-solution-by-pranay-code24-ypyi | # Intuition \n\n\n# Approach : Using HashMap and Sorting\n\n\n# Complexity\n- Time complexity: O(nlogn)\n\n\n- Space complexity: O(n)\n\n\n# Code\n\nclass Sol | pranay_code24 | NORMAL | 2024-07-23T03:45:27.589225+00:00 | 2024-07-23T03:45:27.589253+00:00 | 1,103 | false | <!-- # Intuition -->\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach : Using HashMap and Sorting\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<!... | 7 | 0 | ['Array', 'Hash Table', 'Sorting', 'Java'] | 2 |
sort-array-by-increasing-frequency | C solution using qsort | c-solution-using-qsort-by-duckbill360-ygfs | \n// Let it be global to be used in cmp(). \nint count[201];\n\nint cmp(const void *a, const void *b){\n if(count[*(int*)a + 100] != count[*(int*)b + 100])\n | duckbill360 | NORMAL | 2021-12-16T02:59:50.834925+00:00 | 2021-12-16T02:59:50.834957+00:00 | 605 | false | ```\n// Let it be global to be used in cmp(). \nint count[201];\n\nint cmp(const void *a, const void *b){\n if(count[*(int*)a + 100] != count[*(int*)b + 100])\n return count[*(int*)a + 100] > count[*(int*)b + 100];\n else\n return *(int*)a < *(int*)b;\n}\n\nint* frequencySort(int* nums, int numsSize... | 7 | 0 | ['C'] | 0 |
sort-array-by-increasing-frequency | Bucket Sort | bucket-sort-by-jjqq-dtcu | I know the answer can be in several lines...but during a real interview, what is the interverer expected to see? More from algorithm level, to evaluate your alg | jjqq | NORMAL | 2021-11-15T06:34:51.525916+00:00 | 2021-11-15T06:34:51.525948+00:00 | 715 | false | I know the answer can be in several lines...but during a real interview, what is the interverer expected to see? More from algorithm level, to evaluate your algorithm skills (instead of checking how many default libraries/built-in you can remember)?\n\nHere is a pure bucket sort...\n\n```\nclass Solution {\n public ... | 7 | 0 | ['Bucket Sort', 'Java'] | 0 |
sort-array-by-increasing-frequency | Faster than 95% using lambda function and sort | faster-than-95-using-lambda-function-and-m3bp | \nfrom collections import Counter\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n \n di=Counter(nums)\n li=l | ana_2kacer | NORMAL | 2021-06-20T20:19:05.712320+00:00 | 2021-06-20T20:19:05.712359+00:00 | 1,279 | false | ```\nfrom collections import Counter\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n \n di=Counter(nums)\n li=list(di.items())\n \n #keep a list of frequency elements and their values[val,freq]\n \n li.sort(key=lambda x:(x[1],-x[0]))\n ... | 7 | 0 | ['Sorting', 'Python', 'Python3'] | 2 |
sort-array-by-increasing-frequency | C++ Soln || Beats 100% 🔥|| Easy || Comparator || Lambda Function | c-soln-beats-100-easy-comparator-lambda-7vj8m | Intuition\nThe goal of this problem is to sort the elements of the array based on their frequency in ascending order. If two elements have the same frequency, t | kk_the_omniscient | NORMAL | 2024-07-23T04:28:21.893781+00:00 | 2024-07-23T04:28:21.893813+00:00 | 1,814 | false | # Intuition\nThe goal of this problem is to sort the elements of the array based on their frequency in ascending order. If two elements have the same frequency, they should be sorted by their value in descending order. This ensures that less frequent elements appear earlier, and for elements with the same frequency, th... | 6 | 0 | ['C++'] | 0 |
sort-array-by-increasing-frequency | C# Solution for Sort Array In Increasing Frequency Problem | c-solution-for-sort-array-in-increasing-bq596 | Intuition\n Describe your first thoughts on how to solve this problem. \nIn C#, we can use a Dictionary for counting frequencies, followed by a sorted list to m | Aman_Raj_Sinha | NORMAL | 2024-07-23T03:45:42.713483+00:00 | 2024-07-23T03:45:42.713503+00:00 | 621 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIn C#, we can use a Dictionary for counting frequencies, followed by a sorted list to maintain the elements by their frequency. Here\u2019s\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.\tCount Frequencies: Use... | 6 | 0 | ['C#'] | 1 |
sort-array-by-increasing-frequency | Aditya Verma Approach || Easy to understand | aditya-verma-approach-easy-to-understand-q8t0 | 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 | yc06311 | NORMAL | 2023-08-08T14:14:28.157911+00:00 | 2023-08-08T14:14:28.157938+00:00 | 860 | 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)$$ --... | 6 | 0 | ['C++'] | 2 |
sort-array-by-increasing-frequency | Java Most Possible Solution | java-most-possible-solution-by-janhvi__2-lzcr | \n# Complexity\n- Time complexity:O(N^2)\n Add your time complexity here, e.g. O(n) \n\n# Code\n\nclass Solution {\n public int[] frequencySort(int[] nums) { | Janhvi__28 | NORMAL | 2022-12-15T17:35:05.899188+00:00 | 2022-12-15T17:35:05.899226+00:00 | 2,417 | false | \n# Complexity\n- Time complexity:O(N^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n int[] cnt = new int[201];\n List<Integer> t = new ArrayList<>();\n for (int v : nums) {\n v += 100;\n ... | 6 | 0 | ['Java'] | 0 |
sort-array-by-increasing-frequency | Easy C++ Solution using unordered_map | easy-c-solution-using-unordered_map-by-t-lnwa | \n# Code\n\nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map<int,int> mp;\n for(int i : nums){\n | tata32000 | NORMAL | 2022-12-03T14:57:28.179582+00:00 | 2022-12-03T14:57:28.179603+00:00 | 1,425 | false | \n# Code\n```\nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map<int,int> mp;\n for(int i : nums){\n mp[i]++;\n }\n sort(nums.begin(), nums.end(), [&](int n1, int n2){\n if(mp[n1] == mp[n2]){\n return n1 > n2;\n... | 6 | 0 | ['Hash Table', 'Sorting', 'C++'] | 0 |
sort-array-by-increasing-frequency | C++ solution || Using Priority queue || Beginner friendly | c-solution-using-priority-queue-beginner-cg62 | I have used unordered map instead of ordered map because insertion of an element in unordered map is O(1) time complexity.\n\n vector<int> frequencySort(vector< | jumboclif42 | NORMAL | 2022-03-22T15:49:04.293705+00:00 | 2022-03-23T04:04:59.351400+00:00 | 312 | false | ``` I have used unordered map instead of ordered map because insertion of an element in unordered map is O(1) time complexity.```\n```\n vector<int> frequencySort(vector<int>& a) {\n int n=a.size();\n vector<int>v;\n unordered_map<int,int>mp;\n for(int i=0;i<n;i++)\n mp[a[i]]++;\n... | 6 | 0 | [] | 3 |
sort-array-by-increasing-frequency | C++ || Map and Priority Queue | c-map-and-priority-queue-by-gunjan-g-uxkl | Approach: Use an unordered map for storing frequency of numbers present. Then, a priority queue with custom comparator class is used to store the numbers accord | gunjan-g | NORMAL | 2022-01-14T16:17:00.192896+00:00 | 2022-01-20T06:45:09.325965+00:00 | 598 | false | Approach: Use an unordered map for storing frequency of numbers present. Then, a priority queue with custom comparator class is used to store the numbers accordingly. Here is the code implementation.\n\n```\nclass compare{\n public:\n bool operator()(pair<int,int> n1, pair<int,int> n2){\n if(n1.second==n2.... | 6 | 1 | ['C', 'Heap (Priority Queue)'] | 2 |
sort-array-by-increasing-frequency | [Python] Sort on (count,-value), 3 Lines | python-sort-on-count-value-3-lines-by-ra-h4e0 | Have the sort key be the count of occurrences, and the negative of the value. O(nlogn),O(n) time and space.\n\n\nclass Solution:\n def frequencySort(self, nu | raymondhfeng | NORMAL | 2020-10-31T16:02:21.255787+00:00 | 2020-10-31T16:02:21.255829+00:00 | 727 | false | Have the sort key be the count of occurrences, and the negative of the value. O(nlogn),O(n) time and space.\n\n```\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n counter = collections.Counter(nums)\n nums.sort(key=lambda x: (counter[x],-x))\n return nums\n``` | 6 | 2 | [] | 4 |
sort-array-by-increasing-frequency | 🔢💯 Ace Frequency Sorting! 🚀✨ Simple & Effective Python Solution! 🎓🔥 | ace-frequency-sorting-simple-effective-p-fmxe | Intuition\n Describe your first thoughts on how to solve this problem. \nTo sort elements of an array based on their frequency and then by their value in decrea | LinhNguyen310 | NORMAL | 2024-07-23T14:11:50.283049+00:00 | 2024-07-23T14:11:50.283087+00:00 | 333 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo sort elements of an array based on their frequency and then by their value in decreasing order if frequencies are the same, we can use a frequency dictionary to keep track of how often each number appears. Then, we can use this informa... | 5 | 0 | ['Python'] | 1 |
sort-array-by-increasing-frequency | beat 98.94% 🔥🔥🔥 | beat-9894-by-ahmed_kazi-6tvh | \n\n# Intuition\nThe problem requires us to sort an array based on the frequency of its elements. If multiple elements have the same frequency, they should be s | Ahmed_Kazi | NORMAL | 2024-07-23T09:31:46.721909+00:00 | 2024-07-23T09:31:46.721936+00:00 | 158 | false | \n\n# Intuition\nThe problem requires us to sort an array based on the frequency of its elements. If multiple elements have the same frequency, they should be sorted in decreasing ord... | 5 | 0 | ['JavaScript'] | 0 |
sort-array-by-increasing-frequency | JAVA Solution Explained in HINDI | java-solution-explained-in-hindi-by-the_-dvt6 | https://youtu.be/-WWyNaS1lVk\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote | The_elite | NORMAL | 2024-07-23T06:17:53.279509+00:00 | 2024-07-23T06:17:53.279532+00:00 | 537 | false | https://youtu.be/-WWyNaS1lVk\n\nFor explanation, please watch the above video and do like, share and subscribe the channel. \u2764\uFE0F Also, please do upvote the solution if you liked it.\n\n# Subscribe:- [ReelCoding](https://www.youtube.com/@reelcoding?sub_confirmation=1)\n\n## Subscribe Goal:- 600\n## Current Subsc... | 5 | 0 | ['Java'] | 1 |
sort-array-by-increasing-frequency | 🌟🔥 Easy Solution and Detailed Explanation || ✅ C++ || ✅ Java || ✅ Python 🔥🌟 | easy-solution-and-detailed-explanation-c-0lmt | Approach\n### Step 1: Counting Frequencies \uD83D\uDCCA\nWe start by creating a HashMap to count the frequency of each element in the array.\n\njava\nHashMap<In | originalpandacoder | NORMAL | 2024-07-23T03:38:47.985526+00:00 | 2024-07-23T03:38:47.985559+00:00 | 1,933 | false | # Approach\n### Step 1: Counting Frequencies \uD83D\uDCCA\nWe start by creating a `HashMap` to count the frequency of each element in the array.\n\n```java\nHashMap<Integer, Integer> map = new HashMap<>();\nfor (int i = 0; i < nums.length; i++) {\n map.put(nums[i], map.getOrDefault(nums[i], 0) + 1);\n}\n```\n- **Exp... | 5 | 0 | ['Array', 'Hash Table', 'Sorting', 'Python', 'C++', 'Java'] | 4 |
sort-array-by-increasing-frequency | Counting with Bucket Sort | Python | counting-with-bucket-sort-python-by-prag-mvag | Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n | pragya_2305 | NORMAL | 2024-07-23T02:47:48.434858+00:00 | 2024-07-23T02:47:48.434882+00:00 | 325 | false | # Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n count = Counter(nums) #O(n)\n freq = [[] for _ in range(len(nums)+1)] #O(n)\n\n for key,val in count.items(): #O(n)\n freq[v... | 5 | 0 | ['Array', 'Hash Table', 'Sorting', 'Python', 'Python3'] | 1 |
sort-array-by-increasing-frequency | ✅ Simple Heap Solution | Python | simple-heap-solution-python-by-rhuang53-htnt | Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n# Code\n\nfrom collections import Counter\nfrom heapq import heappop, heappush\nclass Sol | rhuang53 | NORMAL | 2024-07-23T00:57:09.339749+00:00 | 2024-07-23T00:57:09.339780+00:00 | 466 | false | # Complexity\n- Time complexity: O(nlogn)\n\n- Space complexity: O(n)\n\n# Code\n```\nfrom collections import Counter\nfrom heapq import heappop, heappush\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n freq = Counter(nums)\n\n heap = []\n for num in freq:\n ... | 5 | 0 | ['Array', 'Sorting', 'Heap (Priority Queue)', 'Python3'] | 1 |
sort-array-by-increasing-frequency | Java | No maps, only arrays | Sorting | Clean code | java-no-maps-only-arrays-sorting-clean-c-vcvc | 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 here, e.g. O(n) \ | judgementdey | NORMAL | 2024-07-23T00:17:06.458663+00:00 | 2024-07-23T00:17:06.458693+00:00 | 4,227 | false | # 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 here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n var freq = new int[201][2];\n\n for (var i=... | 5 | 0 | ['Array', 'Sorting', 'Java'] | 4 |
sort-array-by-increasing-frequency | Concise LINQ solution | concise-linq-solution-by-dungtranm65-b8e1 | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nWith C# you can make us | dungtranm65 | NORMAL | 2023-11-16T02:56:59.402072+00:00 | 2023-11-16T02:56:59.402095+00:00 | 163 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWith C# you can make use of LINQ. For this problem, LINQ can provide a concise solution with each method in the chain is self-explaind and following the stated require... | 5 | 0 | ['C#'] | 1 |
sort-array-by-increasing-frequency | EASY AND EFFICIENT SOLUTION C++ | easy-and-efficient-solution-c-by-king_of-rkbg | Intuition\n Describe your first thoughts on how to solve this problem. \nEasy C++ Solution Using Lambda Function and Hash Table.\n# Approach\n Describe your app | King_of_Kings101 | NORMAL | 2023-10-06T21:50:39.931280+00:00 | 2023-10-06T21:50:39.931297+00:00 | 823 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nEasy C++ Solution Using Lambda Function and Hash Table.\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\n- Space ... | 5 | 0 | ['Hash Table', 'Sorting', 'C++'] | 1 |
sort-array-by-increasing-frequency | C++ using Map || With Explanation... | c-using-map-with-explanation-by-sagarkes-y5tt | \nclass Solution {\npublic:\n static bool comp(pair<int,int>p,pair<int,int>q)\n //first column stores frequency i.e duplicates and second column stores va | sagarkesharwnnni | NORMAL | 2022-08-04T20:14:47.051234+00:00 | 2022-08-04T20:14:47.051265+00:00 | 2,003 | false | ```\nclass Solution {\npublic:\n static bool comp(pair<int,int>p,pair<int,int>q)\n //first column stores frequency i.e duplicates and second column stores value\n {//if the duplicates are equal then we will return by greater value first...\n if(p.first==q.first)\n {\n return p.second>q.second;\n }\n ///... | 5 | 0 | ['C'] | 0 |
sort-array-by-increasing-frequency | [JavaScript] Easy to understand - detailed explanation with map or array | javascript-easy-to-understand-detailed-e-1ozm | Core Strategy\n\nThe purpose of this problem is to sort the array with custom rules. It\'s straightforward, but we need to do more:\n- we need to count the freq | poppinlp | NORMAL | 2022-03-07T04:42:36.564432+00:00 | 2022-03-07T04:51:07.614859+00:00 | 980 | false | ## Core Strategy\n\nThe purpose of this problem is to sort the array with custom rules. It\'s straightforward, but we need to do more:\n- we need to count the frequency first since we don\'t have it\n- we need to do the sorting with frequency and value\n\nFor the first step, we coud use a map or an array to do the coun... | 5 | 0 | ['JavaScript'] | 1 |
sort-array-by-increasing-frequency | [C++] Priority Queue + Map | Comments for Easy Understanding 📌 | c-priority-queue-map-comments-for-easy-u-9u03 | Before you see this solution, I would highly suggest you to try this below problem :\n\uD83D\uDC49 https://leetcode.com/problems/top-k-frequent-elements/\n\nIf | yourdankfella | NORMAL | 2021-07-21T08:28:57.571326+00:00 | 2022-02-27T09:39:26.362554+00:00 | 494 | false | **Before you see this solution, I would highly suggest you to try this below problem :**\n\uD83D\uDC49 ***https://leetcode.com/problems/top-k-frequent-elements/***\n\n**If you solved the above problem, that\'s great. You can try again this problem and if still can\'t, then continue seeing this solution.** \n**In case ... | 5 | 0 | ['Heap (Priority Queue)'] | 1 |
sort-array-by-increasing-frequency | Java Solution with MinHeap and HashMap | java-solution-with-minheap-and-hashmap-b-j0yf | \nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer, Integer> map = new HashMap<>();\n int sortedArr[] = new int[nums.l | lord_voldemort | NORMAL | 2021-04-05T17:23:36.767013+00:00 | 2021-04-05T17:23:36.767044+00:00 | 372 | false | ```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer, Integer> map = new HashMap<>();\n int sortedArr[] = new int[nums.length];\n for(int num: nums) {\n map.put(num, map.getOrDefault(num, 0) + 1);\n }\n Queue<Integer> minHeap = new PriorityQueue... | 5 | 0 | [] | 1 |
sort-array-by-increasing-frequency | C++ Solution | c-solution-by-vwo50-ah44 | \nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map<int, int> counter;\n \n for (const auto& nu | vwo50 | NORMAL | 2021-03-05T03:42:02.451420+00:00 | 2021-03-05T03:42:02.451464+00:00 | 689 | false | ```\nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map<int, int> counter;\n \n for (const auto& num : nums) counter[num]++; \n \n sort(nums.begin(), nums.end(), [&](int a, int b) {\n return counter[a] < counter[b] || (counter[a] =... | 5 | 1 | ['C'] | 1 |
sort-array-by-increasing-frequency | [Java] Solution using custom Sort | java-solution-using-custom-sort-by-vinsi-grzm | \nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer, Integer> map = new HashMap<>();\n for (int i : nums)\n | vinsinin | NORMAL | 2021-03-04T03:52:59.482943+00:00 | 2021-03-04T03:52:59.482988+00:00 | 999 | false | ```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer, Integer> map = new HashMap<>();\n for (int i : nums)\n map.put(i, map.getOrDefault(i,0) + 1);\n List<Map.Entry<Integer, Integer>> list = new ArrayList(map.entrySet());\n Collections.sort(list, (a,b)... | 5 | 0 | ['Java'] | 2 |
sort-array-by-increasing-frequency | Go Solution | go-solution-by-0xedb-ywlp | go\nfunc frequencySort(nums []int) []int {\n seen := map[int]int{}\n\n\tfor _, v := range nums {\n\t\tseen[v]++\n\t}\n\n sort.Slice(nums, func(i, j int) b | 0xedb | NORMAL | 2020-11-12T21:55:14.592565+00:00 | 2020-11-12T21:55:14.592592+00:00 | 348 | false | ```go\nfunc frequencySort(nums []int) []int {\n seen := map[int]int{}\n\n\tfor _, v := range nums {\n\t\tseen[v]++\n\t}\n\n sort.Slice(nums, func(i, j int) bool{\n if seen[nums[i]] == seen[nums[j]] {\n return nums[j] < nums[i]\n }\n \n return seen[nums[i]] < seen[nums[j]]\n ... | 5 | 0 | ['Go'] | 0 |
sort-array-by-increasing-frequency | [Java] Sort using custom (frequency) comparator | java-sort-using-custom-frequency-compara-pw1q | Calculate the occurence of each number and store it in a hashmap\n2. Define a custom comparator to sort first based on frequency and then based on value\n3. Fil | shyampandya | NORMAL | 2020-10-31T16:09:21.075119+00:00 | 2020-10-31T16:09:21.075147+00:00 | 1,166 | false | 1. Calculate the occurence of each number and store it in a hashmap\n2. Define a custom comparator to sort first based on frequency and then based on value\n3. Fill into the result array\n\n```\npublic int[] frequencySort(int[] nums) {\n Map<Integer, Integer> freqCount = new HashMap();\n for (int n : nums... | 5 | 1 | ['Java'] | 0 |
sort-array-by-increasing-frequency | Easy to understand || Sorting || Mapping | easy-to-understand-sorting-mapping-by-ji-c3bz | 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 | jitenagarwal20 | NORMAL | 2024-07-26T16:45:43.917176+00:00 | 2024-07-26T16:45:43.917218+00:00 | 39 | 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\n- Space complexity: O(n)\n<!-- Add your space complexity here, ... | 4 | 0 | ['C++'] | 0 |
sort-array-by-increasing-frequency | Programmatic Approach || Implementation through Frequency Array || | programmatic-approach-implementation-thr-58v9 | Intuition\nChecking the Constraints you have -100 <= nums[i] <= 100 values which sums upto 201. It gives me an idea of using a frequency Array rather than a STL | KSR-68 | NORMAL | 2024-07-23T07:56:40.625157+00:00 | 2024-07-23T07:56:40.625182+00:00 | 557 | false | # Intuition\nChecking the Constraints you have `-100 <= nums[i] <= 100` values which sums upto 201. It gives me an idea of using a frequency Array rather than a `STL <MAP>`.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFrequency Array stores numbers in sorted order which reduces the time comp... | 4 | 0 | ['Array', 'Sorting', 'C++'] | 0 |
sort-array-by-increasing-frequency | Easy Hash Table Sorting solution | Full Explaination | easy-hash-table-sorting-solution-full-ex-ejmz | Intuition\nThe problem requires us to sort an array of integers based on their frequency of occurrence. If two numbers have the same frequency, they should be s | jaitaneja333 | NORMAL | 2024-07-23T07:45:42.443787+00:00 | 2024-07-23T12:34:40.378648+00:00 | 434 | false | # Intuition\nThe problem requires us to sort an array of integers based on their frequency of occurrence. If two numbers have the same frequency, they should be sorted by their values in descending order.\n\n# To achieve this:\n\nCount Frequencies: First, we need to determine how often each number appears in the array.... | 4 | 0 | ['Array', 'Hash Table', 'Sorting', 'C++'] | 0 |
sort-array-by-increasing-frequency | Beats 100% || Explained with Intuition and Diagram || 0ms | beats-100-explained-with-intuition-and-d-kul1 | Intuition\n Describe your first thoughts on how to solve this problem. \nGiven the constraints -100 <= nums[i] <= 100, you can count the frequency of elements u | atharvf14t | NORMAL | 2024-07-23T05:59:32.936886+00:00 | 2024-07-23T05:59:32.936919+00:00 | 1,349 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGiven the constraints -100 <= nums[i] <= 100, you can count the frequency of elements using an array where the index represents the value shifted by 100 (i.e., freq[x + 100] for x in nums). Then, sort it using a lambda function, which is ... | 4 | 0 | ['C++'] | 2 |
sort-array-by-increasing-frequency | Sort Frequency to Number Mapping As Per Prolem Statement | Java | C++ | [Video Solution] | sort-frequency-to-number-mapping-as-per-fejtb | Intuition, approach, and complexity discussed in video solution in detail\n\n# Code\nJava\n\nclass Solution {\n public int[] frequencySort(int[] nums) {\n | Lazy_Potato_ | NORMAL | 2024-07-23T04:40:44.311900+00:00 | 2024-07-23T04:40:44.311936+00:00 | 730 | false | # Intuition, approach, and complexity discussed in video solution in detail\n\n# Code\nJava\n```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer, Integer> numFreqMp = new HashMap<>();\n for(var num : nums){\n numFreqMp.put(num, numFreqMp.getOrDefault(num, 0)+1);\n ... | 4 | 1 | ['Array', 'Hash Table', 'Sorting', 'C++', 'Java'] | 3 |
sort-array-by-increasing-frequency | 🔥🔥 Explicación y Resolución Del Ejercicio En Español Java | Python | PHP | JavaScript | C++ 🔥🔥 | explicacion-y-resolucion-del-ejercicio-e-9po8 | Lectura\n1636 Sort Array by Increasing Frequency\n\nDado un arreglo de enteros, hay que ordenarlo en orden creciente seg\xFAn la frecuencia de los valores. \nSi | hermescoder02 | NORMAL | 2024-07-23T03:34:00.979097+00:00 | 2024-07-23T03:42:05.522967+00:00 | 244 | false | # Lectura\n1636 Sort Array by Increasing Frequency\n\nDado un arreglo de enteros, hay que ordenarlo en orden creciente seg\xFAn la frecuencia de los valores. \nSi dichos valores tienen la misma frecuencia, ord\xE9nelos en orden decreciente.\n\nEntrada: nums = [2,3,1,3,2]\nSalida: [1,3,3,2,2]\n\nExplicaci\xF3n: \'2\' y ... | 4 | 0 | ['Array', 'Hash Table', 'PHP', 'Sorting', 'Python', 'C++', 'Java', 'JavaScript'] | 0 |
sort-array-by-increasing-frequency | using HashMap || PriorityQueue || beats 98% || | using-hashmap-priorityqueue-beats-98-by-15r1y | 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 | tausif_02 | NORMAL | 2023-04-19T07:54:25.416869+00:00 | 2023-04-19T07:54:25.416899+00:00 | 481 | 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 O(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $... | 4 | 0 | ['Heap (Priority Queue)', 'Java'] | 0 |
sort-array-by-increasing-frequency | Java | Efficient | 1 ms | PriorityQueue | HashMap | java-efficient-1-ms-priorityqueue-hashma-cl1w | \n# Complexity\n- Time complexity:\nO ( n )\n\n- Space complexity:\nO ( n )\n\n# Code\n\nclass Solution {\n class Pair{\n int num;\n int freq;\ | Aditi_sinha123 | NORMAL | 2022-12-30T17:23:02.965867+00:00 | 2022-12-30T17:23:02.965932+00:00 | 2,615 | false | \n# Complexity\n- Time complexity:\nO ( n )\n\n- Space complexity:\nO ( n )\n\n# Code\n```\nclass Solution {\n class Pair{\n int num;\n int freq;\n Pair(int num, int freq){\n this.num=num;\n this.freq=freq;\n }\n }\n public int[] frequencySort(int[] nums) {\n ... | 4 | 0 | ['Hash Table', 'Heap (Priority Queue)', 'Java'] | 2 |
sort-array-by-increasing-frequency | Solution by using Priority Queue and Comparator in C++✅✅ | solution-by-using-priority-queue-and-com-a9qe | \n\n\n#define pii pair<int, int>\n\nclass MyComp\n{\npublic:\n bool operator()(pii const &p1, pii p2)\n {\n if (p1.first == p2.first)\n {\n | shubhz_07 | NORMAL | 2022-12-03T07:03:41.153147+00:00 | 2022-12-03T07:03:41.153202+00:00 | 538 | false | \n```\n\n#define pii pair<int, int>\n\nclass MyComp\n{\npublic:\n bool operator()(pii const &p1, pii p2)\n {\n if (p1.first == p2.first)\n {\n return p1.second <p2.second;\n }\n return p1.first >p2.first;\n }\n};\n\nclass Solution\n{\npublic:\n vector<int> frequencySor... | 4 | 0 | ['C'] | 2 |
sort-array-by-increasing-frequency | Java | TreeMap | ArrayList | Sorting | Easy Solution | java-treemap-arraylist-sorting-easy-solu-jb2b | \nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer,Integer> map1 = new TreeMap<>();\n for(int i: nums)\n ma | Divyansh__26 | NORMAL | 2022-09-13T05:10:03.016740+00:00 | 2022-09-13T05:10:03.016780+00:00 | 1,476 | false | ```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n Map<Integer,Integer> map1 = new TreeMap<>();\n for(int i: nums)\n map1.put(i,map1.getOrDefault(i,0)+1);\n Map<Integer,List<Integer>> map2 = new TreeMap<>();\n for(Map.Entry m: map1.entrySet()){\n int ... | 4 | 0 | ['Array', 'Tree', 'Sorting', 'Java'] | 0 |
sort-array-by-increasing-frequency | Simple Java Solution Using HashMap and Comparator | simple-java-solution-using-hashmap-and-c-dcnd | \nclass Solution {\n public int[] frequencySort(int[] nums) {\n HashMap<Integer,Integer> hm=new HashMap<>(); //Creating frequency map\n for(int | harsh7578 | NORMAL | 2022-08-06T06:53:27.067015+00:00 | 2022-08-06T06:53:27.067054+00:00 | 696 | false | ```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n HashMap<Integer,Integer> hm=new HashMap<>(); //Creating frequency map\n for(int x : nums)\n {\n if(hm.containsKey(x))\n {\n hm.put(x,hm.get(x)+1);\n }\n else\n ... | 4 | 0 | ['Java'] | 1 |
sort-array-by-increasing-frequency | Java Self Explanatory Easy To Understand 98% Faster | java-self-explanatory-easy-to-understand-x1e4 | \nclass Solution {\n public int[] frequencySort(int[] nums) {\n HashMap<Integer,Integer> map = new HashMap<>();\n for(int i:nums) map.put(i,map | bharat194 | NORMAL | 2022-03-05T19:30:29.206921+00:00 | 2022-03-05T19:30:56.393958+00:00 | 1,403 | false | ```\nclass Solution {\n public int[] frequencySort(int[] nums) {\n HashMap<Integer,Integer> map = new HashMap<>();\n for(int i:nums) map.put(i,map.getOrDefault(i,0)+1);\n int[][] arr = new int[map.size()][2];\n int idx=0;\n for(int i:map.keySet()){\n arr[idx][0] = i;\n ... | 4 | 0 | ['Java'] | 0 |
sort-array-by-increasing-frequency | Easy and Explained C++ code | lambda expression | easy-and-explained-c-code-lambda-express-llhj | \nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map <int,int> mp;\n // we need to modify our sort func | drv_rawt19 | NORMAL | 2022-02-20T11:23:45.506489+00:00 | 2022-02-20T11:23:45.506521+00:00 | 426 | false | ```\nclass Solution {\npublic:\n vector<int> frequencySort(vector<int>& nums) {\n unordered_map <int,int> mp;\n // we need to modify our sort function to do that we\'ll use \n // lambda fnction\n for(auto x: nums) mp[x]++;\n\t\t// [&](int a , int b) -> syntax of lambda exp. takes two inpu... | 4 | 0 | ['Array', 'C'] | 1 |
sort-array-by-increasing-frequency | Javascript Solution | javascript-solution-by-mbournehalley-uufr | \n/**\n * Time Complexity: O(nlogn)\n * Space Complexity: O(n)\n * @param {number[]} nums\n * @return {number[]}\n */\nconst frequencySort = function (nums) { | mbournehalley | NORMAL | 2021-11-19T04:01:16.739539+00:00 | 2021-11-19T04:03:40.354662+00:00 | 776 | false | ```\n/**\n * Time Complexity: O(nlogn)\n * Space Complexity: O(n)\n * @param {number[]} nums\n * @return {number[]}\n */\nconst frequencySort = function (nums) { \n return nums.sort(compareFrequency(mapFrequency(nums)));\n};\n\n/**\n * @param {number[]} nums\n * @return {number{}}\n */\nconst mapFrequency = function... | 4 | 0 | ['JavaScript'] | 2 |
sort-array-by-increasing-frequency | EZ Python Code For Beginners O(NLogN) | ez-python-code-for-beginners-onlogn-by-s-y8uf | \nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n d={}\n nums.sort()\n nums=nums[::-1]\n for i in nums | SaumyaRai29 | NORMAL | 2021-10-26T09:42:28.666712+00:00 | 2021-10-26T09:42:28.666759+00:00 | 498 | false | ```\nclass Solution:\n def frequencySort(self, nums: List[int]) -> List[int]:\n d={}\n nums.sort()\n nums=nums[::-1]\n for i in nums:\n if i not in d:\n d[i]=0\n d[i]+=1\n ans=[]\n d=dict(sorted(d.items(),key=lambda x:x[1]))\n for ... | 4 | 0 | ['Sorting', 'Python'] | 1 |
sort-array-by-increasing-frequency | Typescript | Clean and simple solution | typescript-clean-and-simple-solution-by-hbm23 | \nfunction frequencySort(nums: number[]): number[] {\n \n const freq: Record<number, number> = {};\n \n nums.forEach(num => freq[num] = (freq[num] | | mihirbhende1201 | NORMAL | 2021-09-26T06:22:40.276795+00:00 | 2021-09-26T06:22:40.276850+00:00 | 264 | false | ```\nfunction frequencySort(nums: number[]): number[] {\n \n const freq: Record<number, number> = {};\n \n nums.forEach(num => freq[num] = (freq[num] || 0) + 1);\n\n return nums.sort((a, b) => freq[a] != freq[b] ? freq[a] - freq[b] : b - a);\n};\n``` | 4 | 0 | ['TypeScript', 'JavaScript'] | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.