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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
permutation-sequence | {{ Swift }} 88% Beat ((Factorial Trix)) [[Trixy Hobbits]] {{ M.A.T.H.L.O.L. }} | swift-88-beat-factorial-trix-trixy-hobbi-io01 | \nclass Solution {\n func getPermutation(_ n: Int, _ k: Int) -> String {\n \n var fac = [Int](repeating: 1, count: n + 1)\n for i in 1.. | nraptis | NORMAL | 2019-06-11T05:20:54.815533+00:00 | 2019-06-11T05:20:54.815568+00:00 | 222 | false | ```\nclass Solution {\n func getPermutation(_ n: Int, _ k: Int) -> String {\n \n var fac = [Int](repeating: 1, count: n + 1)\n for i in 1..<(n+1) { fac[i] = fac[i - 1] * i }\n fac.reverse()\n \n var k = k - 1\n \n var list = [Int](repeating: 0, count: n)\n ... | 4 | 0 | [] | 0 |
permutation-sequence | [[ C++ ]] 100% Beat ((Drooling Slackers + Community College Burnouts => Copy + Paste)) [[Awesome]] | c-100-beat-drooling-slackers-community-c-kvrq | \nclass Solution {\npublic:\n \n string getPermutation(int n, int k) {\n \n int aFac[n + 1];\n \n aFac[0] = 1;\n \n | nraptis | NORMAL | 2019-06-11T04:39:38.944980+00:00 | 2019-06-11T04:39:38.945019+00:00 | 246 | false | ```\nclass Solution {\npublic:\n \n string getPermutation(int n, int k) {\n \n int aFac[n + 1];\n \n aFac[0] = 1;\n \n for (int i=1;i<=n;i++) {\n aFac[i] = i * aFac[i - 1];\n }\n \n char aList[n + 1];\n aList[n] = 0;\n int aListCo... | 4 | 0 | [] | 0 |
permutation-sequence | java 1ms factorial solution with detailed explanation | java-1ms-factorial-solution-with-detaile-jva8 | Apparently, there are n! different permutations for given n. Suppose m is the first element, then there are n - 1! permuations for the rest n - 1 numbers. The c | pangeneral | NORMAL | 2019-04-20T12:29:52.211958+00:00 | 2019-04-20T12:29:52.212000+00:00 | 769 | false | Apparently, there are ```n!``` different permutations for given ```n```. Suppose ```m``` is the first element, then there are ```n - 1!``` permuations for the rest ```n - 1``` numbers. The case is similar to the second element to the nth element. \n\nWith that in mind, we can calculate the ```kth``` permutation from th... | 4 | 0 | ['Java'] | 0 |
permutation-sequence | 6ms Java Solution | 6ms-java-solution-by-mraufc-wari | Let's say n = 5 and k = 40; Currently we have the following individual numbers: 1 2 3 4 5 Among n! = 120 permutations (n-1)! = 24 of them will begin with "1", t | mraufc | NORMAL | 2018-11-07T15:57:30.190691+00:00 | 2018-11-07T15:57:30.190738+00:00 | 594 | false | Let's say n = 5 and k = 40;
Currently we have the following individual numbers:
```
1 2 3 4 5
```
Among **n!** = **120** permutations **(n-1)!** = **24** of them will begin with **"1"**, the next **24** of them will begin with **"2"**, the next **24** will begin with **"3"** and so on.
In which case **40th** element wi... | 4 | 0 | [] | 1 |
permutation-sequence | 🤩Easy Approach using back tracking 🚀 ❗ | easy-approach-using-back-tracking-by-mut-rrgo | IntuitionWe solve this using a backtracking approachComplexity
Time complexity: O(n!)
Generating all permutations has a time complexity of O(n!).
Since we stop | muthupalani | NORMAL | 2025-01-06T10:29:36.820515+00:00 | 2025-01-06T10:29:36.820515+00:00 | 520 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We solve this using a backtracking approach
# Complexity
- Time complexity: O(n!)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
Generating all permutations has a time complexity of O(n!).
Since we stop once the k-th permutation ... | 3 | 0 | ['Python3'] | 1 |
permutation-sequence | Easy C++ Solution | easy-c-solution-by-aradhya_070304-iyb0 | Intuition\nThe problem leverages factorials to determine the position of digits in the kthpermutation by sequentially fixing each digit based on the remaining p | Aradhya_070304 | NORMAL | 2024-08-08T16:52:32.657417+00:00 | 2024-08-08T16:52:32.657454+00:00 | 786 | false | # Intuition\nThe problem leverages factorials to determine the position of digits in the kthpermutation by sequentially fixing each digit based on the remaining permutations.\nBy reducing the problem size iteratively, we efficiently build the desired permutation without generating all permutations.\n\n# Approach\nCalcu... | 3 | 0 | ['Math', 'Recursion', 'C++'] | 0 |
permutation-sequence | One Line Python Solution | one-line-python-solution-by-ntcqwq-r84m | Code\n\nclass Solution:\n def getPermutation(self, n: int, k: int) -> str:\n return \'\'.join(list(map(str, (list(permutations(list(range(1, n+1))))[k | zzzqwq | NORMAL | 2024-07-08T17:30:45.375074+00:00 | 2024-07-08T17:30:45.375107+00:00 | 79 | false | # Code\n```\nclass Solution:\n def getPermutation(self, n: int, k: int) -> str:\n return \'\'.join(list(map(str, (list(permutations(list(range(1, n+1))))[k-1]))))\n``` | 3 | 0 | ['Python3'] | 0 |
permutation-sequence | Using Next Permutation STL✨ | using-next-permutation-stl-by-sajal2212-ksvf | Intuition\nThe problem involves finding the kth permutation of the numbers from 1 to n. The initial intuition seems to generate all permutations up to the kth p | Sajal2212 | NORMAL | 2024-03-03T13:47:24.457534+00:00 | 2024-03-03T13:47:24.457566+00:00 | 332 | false | # Intuition\nThe problem involves finding the kth permutation of the numbers from 1 to n. The initial intuition seems to generate all permutations up to the kth permutation and return it.\n\n# Approach\nThe provided code generates all permutations of the numbers from 1 to n up to the kth permutation using the `next_per... | 3 | 0 | ['C++'] | 2 |
permutation-sequence | C++ | Beats 100% | c-beats-100-by-shubhamagrawal154-ao1t | Intuition\n\nIdea is to calculate each value of the permutation by dividing the complete range into sub-ranges. We will create an array for storing indices of t | shubhamagrawal154 | NORMAL | 2023-12-30T11:57:18.359465+00:00 | 2023-12-30T11:57:18.359498+00:00 | 461 | false | # Intuition\n\nIdea is to calculate each value of the permutation by dividing the complete range into sub-ranges. We will create an array for storing indices of the sub-range and these indices will be used to get the final result.\n\n## ***Look below for illustration:***\n\nLet\'s take an example where `n = 4` and `k =... | 3 | 0 | ['C++'] | 1 |
permutation-sequence | Python 10ms solution | python-10ms-solution-by-sirfurno-8z31 | Intuition\nFor this problem, my first realization was that for each starting number there are (n-1)! possibilites. Eg:\n\nn=4\nfor the starting number 1 the pos | sirfurno | NORMAL | 2023-09-18T21:36:13.132249+00:00 | 2023-09-18T21:36:13.132278+00:00 | 528 | false | # Intuition\nFor this problem, my first realization was that for each starting number there are (n-1)! possibilites. Eg:\n\nn=4\nfor the starting number 1 the possiblities are:\n1,2,3,4\n1,2,4,3\n1,3,2,4\n1,3,4,2\n1,4,2,3\n1,4,3,2\nThere are 6 possibilities which is the same as 3!\nSo with this, we should be able to th... | 3 | 0 | ['Python'] | 1 |
permutation-sequence | C++ Solution || beates 100% || easy to understand | c-solution-beates-100-easy-to-understand-lrrn | \n# Code\n\nclass Solution {\npublic:\n string getPermutation(int n, int k) {\n int fact = 1;\n vector<int> nums;\n string ans = "";\n | harshil_sutariya | NORMAL | 2023-09-12T03:02:03.868746+00:00 | 2023-09-12T03:02:20.043794+00:00 | 301 | false | \n# Code\n```\nclass Solution {\npublic:\n string getPermutation(int n, int k) {\n int fact = 1;\n vector<int> nums;\n string ans = "";\n for(int i=1;i<n;i++){\n fact=fact*i;\n nums.push_back(i);\n }\n nums.push_back(n);\n k = k-1;\n while... | 3 | 0 | ['Math', 'C++'] | 1 |
permutation-sequence | Most optimal solution without using recursion and backtracking with complete exaplanation | most-optimal-solution-without-using-recu-qryz | \n\n# Approach\nThe given solution aims to find the kth permutation sequence of numbers from 1 to n. It uses a mathematical approach to determine the digits of | priyanshu11_ | NORMAL | 2023-08-28T15:12:04.900128+00:00 | 2023-08-28T15:12:35.820119+00:00 | 799 | false | \n\n# Approach\nThe given solution aims to find the kth permutation sequence of numbers from 1 to n. It uses a mathematical approach to determine the digits of the kth permutation by repeatedly calculating the factorial of (n-1), identifying the next digit in the permutation, and updating the remaining digits.\n\nHere\... | 3 | 0 | ['Math', 'Python', 'C++', 'Java', 'Python3'] | 2 |
permutation-sequence | BEST SOLUTION POSSIBLE | WORLD RECORD | IQ 10000+ | best-solution-possible-world-record-iq-1-8cy7 | Intuition\nSolve more problems you will get the intuition. \n\n# Approach\nArey bindu, dekh agar n=5 hai toh agar mai kisi ek number from 1-5 ko first element b | NayakPenguin | NORMAL | 2023-07-23T00:15:10.471133+00:00 | 2023-07-23T00:15:10.471178+00:00 | 44 | false | # Intuition\nSolve more problems you will get the intuition. \n\n# Approach\nArey bindu, dekh agar n=5 hai toh agar mai kisi ek number from 1-5 ko first element banata hu toh 4! options hoga each ka. \n\nAgar k = 59 hai, then k = (24 + 24 + 11). \nThat means starting mai 3 ayega and uske ander permutions hoga further.\... | 3 | 0 | ['Math', 'Recursion', 'C++'] | 0 |
permutation-sequence | Simple C++ Code | simple-c-code-by-abhradip_360-0wjp | 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 | abhradip_360 | NORMAL | 2023-05-05T16:59:45.227621+00:00 | 2023-05-05T16:59:45.227664+00:00 | 69 | 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)$$ --... | 3 | 0 | ['C++'] | 0 |
permutation-sequence | java Solution beats 100% (sometimes 98%) non recursive | java-solution-beats-100-sometimes-98-non-o74a | Intuition\nIterative traversal and removal of elemnents from the bucket\n# Approach\nthe appraoch is based upon how u take benifit of factorial\n\n# Complexity\ | rajAbhinav | NORMAL | 2023-04-20T06:15:33.518564+00:00 | 2023-04-20T06:15:33.518602+00:00 | 1,387 | false | # Intuition\nIterative traversal and removal of elemnents from the bucket\n# Approach\nthe appraoch is based upon how u take benifit of factorial\n\n# Complexity\n- Time complexity:\nO(N) beats 100%\n\n- Space complexity:\n beats 83%\n# Code\n```\nclass Solution {\n public String getPermutation(int n, int k) {\n ... | 3 | 0 | ['Java'] | 1 |
permutation-sequence | Easy C++ solution | easy-c-solution-by-ddivyassingh-kczj | \n\n\n# Complexity\n- Time complexity:\nO(n^2) \n\n- Space complexity:\nO(n) \n\n# Code\n\nclass Solution {\npublic:\n string getPermutation(int n, int k) {\ | ddivyassingh | NORMAL | 2023-03-21T11:52:33.617636+00:00 | 2023-03-21T11:52:33.617673+00:00 | 9 | false | \n\n\n# Complexity\n- Time complexity:\nO(n^2) \n\n- Space complexity:\nO(n) \n\n# Code\n```\nclass Solution {\npublic:\n string getPermutation(int n, int k) {\n vector<int> nums;\n string ans="";\n k=k-1;\n int fact=1;\n for (int i=0 ; i<n; i++)\n {\n fact=fact*(... | 3 | 0 | ['C++'] | 0 |
permutation-sequence | 3ms || N*N || C++ || SHORT & SWEET CODE || ITERATIVE | 3ms-nn-c-short-sweet-code-iterative-by-y-2a8y | \nclass Solution {\npublic:\n string getPermutation(int n, int k) {\n vector<int> v(n+1,false);\n vector<int> fact(n+1,1);\n for(int i = | yash___sharma_ | NORMAL | 2023-03-18T05:38:04.192075+00:00 | 2023-03-18T05:38:04.192106+00:00 | 4,820 | false | ```\nclass Solution {\npublic:\n string getPermutation(int n, int k) {\n vector<int> v(n+1,false);\n vector<int> fact(n+1,1);\n for(int i = 2; i <= n; i++){\n fact[i] = fact[i-1]*i;\n }\n string ans = "";\n k--;\n for(int i = 1; i <= n; i++){\n i... | 3 | 0 | ['Math', 'C', 'Iterator', 'C++'] | 0 |
permutation-sequence | Java || Beats 99.6% || 1ms runtime || Recursion | java-beats-996-1ms-runtime-recursion-by-uj1he | java []\nclass Solution {\n public String getPermutation(int n, int k) {\n int[] fact = new int[]{1,1,2,6,24,120,720,5040,40320};\n ArrayList<I | nishant7372 | NORMAL | 2023-03-17T16:48:35.132767+00:00 | 2023-03-17T16:48:35.132798+00:00 | 1,287 | false | ``` java []\nclass Solution {\n public String getPermutation(int n, int k) {\n int[] fact = new int[]{1,1,2,6,24,120,720,5040,40320};\n ArrayList<Integer> list = new ArrayList<>();\n for(int i=1;i<=n;i++){\n list.add(i);\n }\n return calc(fact,n,k-1,list,0)+"";\n }\n\... | 3 | 0 | ['Java'] | 0 |
permutation-sequence | 1 Liner Code 😎 | Python | 1-liner-code-python-by-arijitparia2002-i884 | Intuition\n Describe your first thoughts on how to solve this problem. \n1. Using the Permutations to find all the possible permutations.\n2. Sorting in the asc | arijitparia2002 | NORMAL | 2023-03-02T23:21:08.459825+00:00 | 2023-03-02T23:21:08.459872+00:00 | 1,069 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. Using the `Permutations` to find all the possible permutations.\n2. Sorting in the ascending order.\n3. Getting the `k-1` th value, which is a tuple\n4. Converting that tuple in string format.\n5. Returning the result.\n\n# Code\n```\n... | 3 | 1 | ['Python', 'Python3'] | 1 |
permutation-sequence | Beats 99.7% 60. Permutation Sequence with step by step explanation | beats-997-60-permutation-sequence-with-s-66es | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nHere, we use a simple factorial approach. First, we calculate all the fac | Marlen09 | NORMAL | 2023-02-12T14:53:46.691149+00:00 | 2023-02-12T14:53:46.691205+00:00 | 952 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nHere, we use a simple factorial approach. First, we calculate all the factorials up to n, and use that to find the next number to add to the result. We start from the last factorial and keep adding numbers to the result, dec... | 3 | 0 | ['Python', 'Python3'] | 0 |
permutation-sequence | c++ || easy to understand || beats 100 percent || O(n^2) | c-easy-to-understand-beats-100-percent-o-d0ke | please upvote if you like the solution.\n# Code\n\nclass Solution {\npublic:\n string getPermutation(int n, int k) {\n string s = "" ;\n vector | strange6281 | NORMAL | 2023-01-10T05:04:45.465960+00:00 | 2023-04-23T18:16:22.860495+00:00 | 2,180 | false | please upvote if you like the solution.\n# Code\n```\nclass Solution {\npublic:\n string getPermutation(int n, int k) {\n string s = "" ;\n vector<int>ds ;\n for(int i = 1 ; i <= n ; i++){\n ds.push_back(i) ;\n }\n int i = n ;\n while(k!= 0 && i >= 1){\n ... | 3 | 0 | ['C++'] | 2 |
permutation-sequence | C++ | 0ms | Recursive Solution | c-0ms-recursive-solution-by-sameer_22-abse | The basic idea is to decrease the search space. Now, what does this mean, Actually if we want to place a number at the first position then it will be having (n- | Sameer_22 | NORMAL | 2022-10-22T09:47:54.861186+00:00 | 2022-10-22T09:47:54.861233+00:00 | 470 | false | The basic idea is to decrease the search space. Now, what does this mean, Actually if we want to place a number at the first position then it will be having (n-1)! ways to do it. So, let us take an example:\n\nn = 4 and k=9\n\nso, for suppose if we assume our answer will be having \'1\' at 1st position. Now let us writ... | 3 | 0 | [] | 0 |
permutation-sequence | Java optimized solution | java-optimized-solution-by-sharan79-bvqm | Approach : Brute Force\nWill Give TLE\n\nclass Solution {\n \n private void swap(char[] s , int i , int j){\n char temp = s[i];\n s[i] = s[j | Sharan79 | NORMAL | 2022-08-16T22:32:27.833050+00:00 | 2022-08-16T22:32:27.833083+00:00 | 633 | false | ### **Approach : Brute Force**\n**Will Give TLE**\n```\nclass Solution {\n \n private void swap(char[] s , int i , int j){\n char temp = s[i];\n s[i] = s[j];\n s[j] = temp;\n }\n \n private void solve(char[] s , int index , List<String> res){\n if(index == s.length){\n ... | 3 | 0 | ['Backtracking', 'Recursion', 'Java'] | 0 |
permutation-sequence | Simple Mathematical Solution | simple-mathematical-solution-by-ryangray-thq3 | \nclass Solution:\n def getPermutation(self, n: int, k: int) -> str:\n perm, fact = "", factorial(n)\n nums = [ i for i in range(1, n+1) ] #to | ryangrayson | NORMAL | 2022-06-20T18:04:41.659106+00:00 | 2022-06-20T18:04:41.659155+00:00 | 345 | false | ```\nclass Solution:\n def getPermutation(self, n: int, k: int) -> str:\n perm, fact = "", factorial(n)\n nums = [ i for i in range(1, n+1) ] #to keep track of the options left\n for i in range(n, 0, -1):\n fact //= i\n cur_pos = (k-1) // fact #index of next number based ... | 3 | 0 | ['Python'] | 0 |
permutation-sequence | CPP Recursion Easy Solution | cpp-recursion-easy-solution-by-abhishek2-hl7l | \tint count=0;\n string ans;\n void rightrotate(string& s, int i, int j){\n if(i==j)return;\n char temp=s[j];\n for(int k=j-1;k>=i;k- | abhishek23a | NORMAL | 2022-06-07T10:00:22.573013+00:00 | 2022-06-07T10:00:22.573100+00:00 | 199 | false | \tint count=0;\n string ans;\n void rightrotate(string& s, int i, int j){\n if(i==j)return;\n char temp=s[j];\n for(int k=j-1;k>=i;k--){\n s[k+1]=s[k];\n }\n s[i]=temp;\n }\n void leftrotate(string& s, int i, int j){\n if(i==j)return;\n char temp=s... | 3 | 0 | ['Recursion'] | 0 |
largest-number-after-digit-swaps-by-parity | C++|| 0 ms || O(nlogn) || Easy to understand || Commented Explanation || Priority Queue | c-0-ms-onlogn-easy-to-understand-comment-9ki5 | The simple idea is to store even and odd digits of the number num into 2 priority queues (max heap); and then iterate over every digit of num to look for places | gnipun05 | NORMAL | 2022-04-10T05:12:41.582604+00:00 | 2022-04-11T03:42:50.638649+00:00 | 8,890 | false | The simple idea is to store even and odd digits of the number **num** into 2 priority queues (max heap); and then iterate over every digit of **num** to look for places having odd (or even) digits. And then placing the top of the respected queues over those postions.\n\nPlease do upvote if this solution helps.\n\n```\n... | 99 | 1 | ['C', 'Heap (Priority Queue)'] | 14 |
largest-number-after-digit-swaps-by-parity | Concise Java, 9 lines | concise-java-9-lines-by-climberig-l6g8 | Look for a digit on the right that is bigger than the current digit and has the same parity, and swap them.\n(a[j] - a[i]) % 2 == 0 parity check (true if both a | climberig | NORMAL | 2022-04-10T04:11:25.345652+00:00 | 2022-04-10T04:21:42.994353+00:00 | 5,949 | false | Look for a digit on the right that is bigger than the current digit and has the same parity, and swap them.\n```(a[j] - a[i]) % 2 == 0``` parity check (true if both a[j] and a[i] are even or both are odd)\n```java\n public int largestInteger(int n){\n char[] a = String.valueOf(n).toCharArray();\n for(int ... | 56 | 5 | ['Java'] | 19 |
largest-number-after-digit-swaps-by-parity | Python Solution using Sorting | python-solution-using-sorting-by-ancoder-wi2w | Since we need the largest number, what we want is basically to have the larger digits upfront and then the smaller ones. But we are given a parity condition tha | ancoderr | NORMAL | 2022-04-10T04:02:10.466905+00:00 | 2022-04-10T04:34:17.165564+00:00 | 6,310 | false | Since we need the largest number, what we want is basically to have the larger digits upfront and then the smaller ones. But we are given a parity condition that we need to comply to. We are allowed to swap odd digits with odd ones and even with even ones. So we simply maintain two arrays with odd and even digits. The ... | 31 | 1 | ['Python', 'Python3'] | 9 |
largest-number-after-digit-swaps-by-parity | Count Array | count-array-by-votrubac-06zg | Perhaps not as concise - shooting for efficiency (linear time and no string operations).\n\nWe count how much of each number we have in cnt.\n\nThen, we process | votrubac | NORMAL | 2022-04-10T05:40:46.816468+00:00 | 2022-04-11T02:27:48.734234+00:00 | 3,701 | false | Perhaps not as concise - shooting for efficiency (linear time and no string operations).\n\nWe count how much of each number we have in `cnt`.\n\nThen, we process digits in `num` right to left, determine the parity `par`, and use the smallest number with that parity from the `cnt` array.\n\nWe start from `0` for even, ... | 30 | 0 | ['C'] | 7 |
largest-number-after-digit-swaps-by-parity | ✅ C++ | Priority queue | Easy & Concise | O(NlogN ) | c-priority-queue-easy-concise-onlogn-by-r1c98 | \nclass Solution {\npublic:\n int largestInteger(int num) {\n string s=to_string(num); //first covert the num into a string for easy traversal\n | rupam66 | NORMAL | 2022-04-10T05:32:49.695668+00:00 | 2022-04-10T07:19:53.283279+00:00 | 2,358 | false | ```\nclass Solution {\npublic:\n int largestInteger(int num) {\n string s=to_string(num); //first covert the num into a string for easy traversal\n priority_queue<int> odd, even; // then take 2 priority queue odd & even\n for(auto x: s){\n int tmp=x-\'0\'; // covert char to int\n ... | 29 | 0 | ['C', 'Sorting', 'Heap (Priority Queue)'] | 6 |
largest-number-after-digit-swaps-by-parity | sorting odd and even | sorting-odd-and-even-by-yashgarala29-drl1 | \nclass Solution {\npublic:\n int largestInteger(int num) {\n vector<int> odd,even,arr;\n while(num)\n {\n int digit =num%10; | yashgarala29 | NORMAL | 2022-04-10T04:01:39.945990+00:00 | 2022-04-10T04:01:39.946015+00:00 | 2,555 | false | ```\nclass Solution {\npublic:\n int largestInteger(int num) {\n vector<int> odd,even,arr;\n while(num)\n {\n int digit =num%10;\n num=num/10;\n if(digit%2==0)\n {\n even.push_back(digit);\n }\n else\n {\... | 19 | 1 | ['Sorting'] | 2 |
largest-number-after-digit-swaps-by-parity | [Java] solution using two priority queue | java-solution-using-two-priority-queue-b-m4f8 | \nclass Solution {\n public int largestInteger(int num) {\n PriorityQueue<Integer> opq = new PriorityQueue<>();\n PriorityQueue<Integer> epq = | alan24 | NORMAL | 2022-04-10T04:19:27.340073+00:00 | 2022-04-10T04:19:27.340101+00:00 | 2,089 | false | ```\nclass Solution {\n public int largestInteger(int num) {\n PriorityQueue<Integer> opq = new PriorityQueue<>();\n PriorityQueue<Integer> epq = new PriorityQueue<>();\n int bnum = num;\n while(num>0){\n int cur = num%10;\n if(cur%2==1){\n opq.add(cur... | 16 | 0 | ['Heap (Priority Queue)', 'Java'] | 8 |
largest-number-after-digit-swaps-by-parity | [Java] Counting Sort solution [Faster than 100.00% ] | java-counting-sort-solution-faster-than-qez6k | Intuition\n1. Get frequency of all the digits from 0-9\n2. Construct the newNumber by taking the maximum possible digit for that location => odd/even is determi | manidh | NORMAL | 2022-04-10T04:22:56.401419+00:00 | 2022-04-10T04:22:56.401442+00:00 | 2,154 | false | **Intuition**\n1. Get frequency of all the digits from 0-9\n2. Construct the newNumber by taking the maximum possible digit for that location => odd/even is determined by the parity of the value in the original number provided\n\n```\n public int largestInteger(int num) {\n char[] nums = Integer.toString(num).to... | 12 | 0 | ['Sorting', 'Counting Sort', 'Java'] | 3 |
largest-number-after-digit-swaps-by-parity | C++ || Easy Solution || O(n^2) | c-easy-solution-on2-by-raghav_maskara-vlyl | Approach-\n store all digits in an array\n run two loops and check if the second element is greater than the first and their parity is same or not\n If yes, we | raghav_maskara | NORMAL | 2022-04-10T04:32:49.398001+00:00 | 2022-04-10T04:34:13.093101+00:00 | 967 | false | **Approach-**\n* store all digits in an array\n* run two loops and check if the second element is greater than the first and their parity is same or not\n* If yes, we swap the elements.\n* Reconstruct the number using the modified array.\n\n\n```\nclass Solution {\npublic:\n int largestInteger(int num) {\n ve... | 9 | 2 | ['C'] | 2 |
largest-number-after-digit-swaps-by-parity | Largest Number After Digit Swaps By Parity || Efficient Approach | largest-number-after-digit-swaps-by-pari-wcyt | IntuitionThe problem is to rearrange the digits of an integer num to form the largest possible number while maintaining the parity (even or odd) of each digit i | theCode_X | NORMAL | 2025-01-02T13:28:00.493175+00:00 | 2025-01-02T13:28:00.493175+00:00 | 1,193 | false | # Intuition
The problem is to rearrange the digits of an integer num to form the largest possible number while maintaining the parity (even or odd) of each digit in its original position. The core idea is to separate the even and odd digits, sort them in descending order, and then reconstruct the number while preservin... | 7 | 0 | ['Heap (Priority Queue)', 'Java'] | 0 |
largest-number-after-digit-swaps-by-parity | Wrong testcase for input -> 247 !!! output should be 742. | wrong-testcase-for-input-247-output-shou-mbu9 | Please help me to figure it out where i\'m lacking!\n\n\n\n\n\nclass Solution {\npublic:\n int largestInteger(int num) {\n string s = to_string(num);\ | binayKr | NORMAL | 2022-04-27T08:15:09.294816+00:00 | 2022-04-28T06:33:24.821367+00:00 | 352 | false | ## ***Please help me to figure it out where i\'m lacking!***\n\n\n\n\n```\nclass Solution {\npublic:\n int largestInteger(int num) {\n string s = to_string(num);\n int n = s.size();\n pri... | 7 | 0 | [] | 2 |
largest-number-after-digit-swaps-by-parity | Sort and put them back || With intuition || 7 lines | sort-and-put-them-back-with-intuition-7-fhdmk | Intuition:\n We can simply extract the even and odd in different strings and sort them in decreasing order and put them back in main string.\n Problem Occurs : | xxvvpp | NORMAL | 2022-04-10T04:06:49.428021+00:00 | 2022-04-10T06:07:43.464685+00:00 | 1,000 | false | **Intuition**:\n We can simply `extract the even and odd in different strings and sort them in decreasing order and put them back in main string`.\n **Problem Occurs** : How we will differentiate the even and odd position for puting the odd and even back.\n **Solution**: We will put all even at even element position a... | 7 | 0 | ['C'] | 1 |
largest-number-after-digit-swaps-by-parity | C++ Solution || Fully Commented || 💯% fast | c-solution-fully-commented-fast-by-nitin-7a6z | \n\n# Code\n\nclass Solution {\npublic:\n int largestInteger(int num) {\n priority_queue<int>odd,even;//To store the even and odd values in descending o | NitinSingh77 | NORMAL | 2023-03-09T15:58:42.609726+00:00 | 2023-03-23T15:37:01.170353+00:00 | 1,358 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int largestInteger(int num) {\n priority_queue<int>odd,even;//To store the even and odd values in descending order separately;\n\n vector<int>seq,nitin; //Seq vector to store the sequence of odd and even occurrences and nitin vector to store the values of pri... | 6 | 0 | ['Heap (Priority Queue)', 'C++'] | 0 |
largest-number-after-digit-swaps-by-parity | Python||Heap soln | pythonheap-soln-by-nitishjha21-y5mu | ```\nclass Solution:\n def largestInteger(self, num: int) -> int:\n evenHeap = []\n oddHeap = []\n heapq.heapify(evenHeap)\n heap | NitishJha21 | NORMAL | 2022-04-27T08:23:08.444180+00:00 | 2022-04-27T08:23:08.444221+00:00 | 713 | false | ```\nclass Solution:\n def largestInteger(self, num: int) -> int:\n evenHeap = []\n oddHeap = []\n heapq.heapify(evenHeap)\n heapq.heapify(oddHeap)\n num = list(str(num))\n for i in num:\n if int(i)%2:\n heapq.heappush(oddHeap,-int(i))\n ... | 6 | 0 | ['Heap (Priority Queue)', 'Python'] | 1 |
largest-number-after-digit-swaps-by-parity | 👉 Simple Solution || Sorting || C++ ✅✅ | simple-solution-sorting-c-by-ganesh_1221-0vu5 | \n\nclass Solution {\npublic:\n int largestInteger(int num) {\n \n string s=to_string(num);\n vector<pair<int,char>>odd,even; \n | Ganesh_1221 | NORMAL | 2023-07-19T18:44:39.285462+00:00 | 2023-07-19T18:44:39.285483+00:00 | 1,952 | false | ```\n\nclass Solution {\npublic:\n int largestInteger(int num) {\n \n string s=to_string(num);\n vector<pair<int,char>>odd,even; \n int i=0,j=0;\n \n for(auto i:s){\n if((i-\'0\')%2==0)even.push_back({i-\'0\',i}); // store pair like {2,\'2\'}\n else odd... | 5 | 0 | [] | 0 |
largest-number-after-digit-swaps-by-parity | Largest Number After Digit Swaps by Parity Solution in C++ | largest-number-after-digit-swaps-by-pari-bhcp | 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 | The_Kunal_Singh | NORMAL | 2023-05-16T17:27:52.393735+00:00 | 2023-05-16T17:27:52.393777+00:00 | 676 | 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)$$ -->\nO(nlogn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O... | 5 | 0 | ['C++'] | 0 |
largest-number-after-digit-swaps-by-parity | easy | easy-by-qwerysingr-p9xd | \nclass Solution {\npublic:\n int largestInteger(int numb) {\n \n int num = numb;\n vector<int> e, o, n;\n while (num) {\n | qwerysingr | NORMAL | 2022-05-08T05:53:33.816963+00:00 | 2022-05-08T05:53:33.817002+00:00 | 253 | false | ```\nclass Solution {\npublic:\n int largestInteger(int numb) {\n \n int num = numb;\n vector<int> e, o, n;\n while (num) {\n int d = num % 10;\n if (d & 1) o.push_back(d);\n else e.push_back(d);\n num /= 10;\n }\n \n sort(... | 5 | 0 | [] | 0 |
largest-number-after-digit-swaps-by-parity | simple and easy C++ solution 😍❤️🔥 | simple-and-easy-c-solution-by-shishirrsi-i4eh | if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n\nclass Solution {\npublic:\n int largestInteger(int num) \n {\n string s = to_stri | shishirRsiam | NORMAL | 2024-06-19T21:14:05.467292+00:00 | 2024-06-19T21:14:05.467310+00:00 | 473 | false | # if it\'s help, please up \u2B06 vote! \u2764\uFE0F\n\n\n# Code\n```\nclass Solution {\npublic:\n int largestInteger(int num) \n {\n string s = to_string(num);\n string even, odd;\n for(auto ch:s)\n {\n if(ch%2) odd.push_back(ch);\n else even.push_back(ch);\n ... | 4 | 0 | ['String', 'Sorting', 'C++'] | 3 |
largest-number-after-digit-swaps-by-parity | Both Max Heap and Sorting Solutions with Explanations! 🔢 % 🔥 | both-max-heap-and-sorting-solutions-with-3v61 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem involves rearranging the digits of a given number such that the new number | sirsebastian5500 | NORMAL | 2024-06-09T23:16:36.997703+00:00 | 2024-06-09T23:18:35.722724+00:00 | 267 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves rearranging the digits of a given number such that the new number is the largest possible while maintaining the relative positions of even and odd digits. This means we need to sort the even digits and odd digits sepa... | 4 | 0 | ['Python3'] | 0 |
largest-number-after-digit-swaps-by-parity | C++ Solution || 100% Fast || Easy to Understand | c-solution-100-fast-easy-to-understand-b-27nx | Approach:\n1. We will declare two Priority Queues with the name odd and even to store the odd and even digits from the given number.\n2. We will declare two arr | 01_Unzila | NORMAL | 2023-02-28T13:48:34.068701+00:00 | 2023-02-28T13:48:34.068783+00:00 | 764 | false | **Approach:**\n1. We will declare two Priority Queues with the name **odd** and **even** to store the odd and even digits from the given number.\n2. We will declare two arrays, array **digit** to store all the digits of the given number and other array **res** to store the digits of the required number.\nWe will store ... | 4 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 0 |
largest-number-after-digit-swaps-by-parity | Python easy solution using heap | faster than 99% | python-easy-solution-using-heap-faster-t-tkxg | \nI have maintained two heaps: odd_x and even_x\nIf number is odd push into odd_x else push intoeven_x, also I am adding true (wherever odd number is encountere | wilspi | NORMAL | 2022-08-08T02:05:46.458862+00:00 | 2022-08-08T02:05:46.458890+00:00 | 1,406 | false | \nI have maintained two heaps: `odd_x` and `even_x`\nIf number is odd push into `odd_x` else push into`even_x`, also I am adding true (wherever odd number is encountered) so that its easy to track positions of odd numbers\n\nFor generating ans, I am popping out highest odd number for positions using heap where odd numb... | 4 | 0 | ['Heap (Priority Queue)', 'Python', 'Python3'] | 1 |
largest-number-after-digit-swaps-by-parity | Java || 2 Priority Queues || Easy | java-2-priority-queues-easy-by-devansh28-a2a4 | \nclass Solution {\n public int largestInteger(int num) {\n String numStr = Integer.toString(num);\n PriorityQueue<Integer> oddPQ = new Priorit | devansh2805 | NORMAL | 2022-06-02T10:19:20.586237+00:00 | 2022-06-02T10:19:20.586272+00:00 | 589 | false | ```\nclass Solution {\n public int largestInteger(int num) {\n String numStr = Integer.toString(num);\n PriorityQueue<Integer> oddPQ = new PriorityQueue<>(Collections.reverseOrder());\n PriorityQueue<Integer> evenPQ = new PriorityQueue<>(Collections.reverseOrder());\n for(char digit: numS... | 4 | 0 | ['Heap (Priority Queue)', 'Java'] | 0 |
largest-number-after-digit-swaps-by-parity | Simple | Easy | Sorting | simple-easy-sorting-by-abhinandanmishra1-9br0 | \nclass Solution {\npublic:\n int largestInteger(int num) {\n vector<int> pos;\n vector<int> even,odd;\n int n=num;\n while(n>0){ | abhinandanmishra1 | NORMAL | 2022-04-10T04:56:07.187842+00:00 | 2022-04-10T04:56:07.187875+00:00 | 400 | false | ```\nclass Solution {\npublic:\n int largestInteger(int num) {\n vector<int> pos;\n vector<int> even,odd;\n int n=num;\n while(n>0){\n int k=n%10;\n if(k&1){\n odd.push_back(k);\n pos.push_back(0);\n }else{\n ev... | 4 | 0 | ['C', 'Sorting'] | 0 |
largest-number-after-digit-swaps-by-parity | C++ || SORTING || COMMENTED | c-sorting-commented-by-sahiltuli_31-bfby | \nint largestInteger(int num) {\n \n \n //the idea is to get all even and odd number seaparate\n vector<int> odd;\n vector<in | sahiltuli_31 | NORMAL | 2022-04-10T04:04:26.649855+00:00 | 2022-04-10T04:05:47.641407+00:00 | 441 | false | ```\nint largestInteger(int num) {\n \n \n //the idea is to get all even and odd number seaparate\n vector<int> odd;\n vector<int> even;\n \n string n = to_string(num);\n string nn = n;\n \n for(int i = 0;i < n.size();i++)\n {\n int k ... | 4 | 0 | ['C', 'Sorting'] | 1 |
largest-number-after-digit-swaps-by-parity | [C++] || Brute | c-brute-by-4byx-zfq8 | \nclass Solution {\npublic:\n int largestInteger(int num) {\n string s = to_string(num);\n int n = s.length();\n for(int i = 0 ; i < n ; | 4byx | NORMAL | 2022-04-10T04:00:48.869795+00:00 | 2022-04-10T04:00:48.869830+00:00 | 637 | false | ```\nclass Solution {\npublic:\n int largestInteger(int num) {\n string s = to_string(num);\n int n = s.length();\n for(int i = 0 ; i < n ; i++){\n int f = i;\n int maxi = s[i]-\'0\';\n for(int j = i+1 ; j < n ; j++){\n if((s[i]-\'0\')%2 == 1 and (... | 4 | 1 | ['C'] | 0 |
largest-number-after-digit-swaps-by-parity | SIMPLE MAX-HEAP C++ SOLUTION | simple-max-heap-c-solution-by-jeffrin200-i98p | 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 | Jeffrin2005 | NORMAL | 2024-08-02T09:54:54.522535+00:00 | 2024-08-02T09:54:54.522566+00:00 | 204 | 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(D log D), where D is the number of digits in the number.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexi... | 3 | 0 | ['C++'] | 0 |
largest-number-after-digit-swaps-by-parity | Java Solution | java-solution-by-janhvi__28-t56b | \nclass Solution {\n public int largestInteger(int num) {\n int[] ans = new int[10];\n int x = num;\n while (x != 0) {\n ans[ | Janhvi__28 | NORMAL | 2022-11-07T07:37:51.621442+00:00 | 2022-11-07T07:37:51.621478+00:00 | 1,409 | false | ```\nclass Solution {\n public int largestInteger(int num) {\n int[] ans = new int[10];\n int x = num;\n while (x != 0) {\n ans[x % 10]++;\n x /= 10;\n }\n x = num;\n int result = 0;\n int t = 1;\n while (x != 0) {\n int v = x %... | 3 | 0 | ['Java'] | 0 |
largest-number-after-digit-swaps-by-parity | Odd-Even Approach ||Using Strings || Explained With Comments || C++ | odd-even-approach-using-strings-explaine-590p | \nclass Solution {\npublic:\n int largestInteger(int num) {\n \n string s = to_string(num);\n \n string even=""; // stores all even no. | shubh08am | NORMAL | 2022-09-17T10:39:36.492081+00:00 | 2022-09-17T10:39:36.492126+00:00 | 518 | false | ```\nclass Solution {\npublic:\n int largestInteger(int num) {\n \n string s = to_string(num);\n \n string even=""; // stores all even no.\n string odd=""; // stores all odd no.\n string ans=""; // stores result\n \n //storing odd and even no.\n for(auto&it:... | 3 | 0 | ['String', 'C'] | 0 |
largest-number-after-digit-swaps-by-parity | Using priority queue C++ 0 ms, 100% faster | using-priority-queue-c-0-ms-100-faster-b-1ik0 | \nint largestInteger(int num) {\n string s=to_string(num);\n int n=s.size();\n priority_queue<int> odd;\n priority_queue<int> even;\ | Shreedhar_Kushwaha | NORMAL | 2022-09-12T06:42:26.334669+00:00 | 2022-09-12T06:42:26.334720+00:00 | 525 | false | ```\nint largestInteger(int num) {\n string s=to_string(num);\n int n=s.size();\n priority_queue<int> odd;\n priority_queue<int> even;\n int result=0;\n for(int i=0;i<n;i++){\n if((s[i]-\'0\')%2 ==0)\n even.push(s[i]-\'0\');\n else\n ... | 3 | 0 | ['C', 'Heap (Priority Queue)', 'C++'] | 0 |
largest-number-after-digit-swaps-by-parity | C++|| 0 ms || Easy to understand | c-0-ms-easy-to-understand-by-rishabhteli-41te | \nclass Solution {\npublic:\n bool issame(int a, int b){\n if(a%2==0 && b%2==0) return true;\n else if(a%2!=0 && b%2!=0) return true;\n | rishabhteli14 | NORMAL | 2022-04-12T12:23:02.543517+00:00 | 2023-07-06T08:42:14.423484+00:00 | 115 | false | ```\nclass Solution {\npublic:\n bool issame(int a, int b){\n if(a%2==0 && b%2==0) return true;\n else if(a%2!=0 && b%2!=0) return true;\n return false;\n }\n \n int largestInteger(int num) {\n string str = to_string(num);\n if(str.length()==1){\n return num;\n ... | 3 | 0 | ['C++'] | 0 |
largest-number-after-digit-swaps-by-parity | Rust solution | rust-solution-by-bigmih-sm7w | \nimpl Solution {\n pub fn largest_integer(num: i32) -> i32 {\n use std::collections::BinaryHeap;\n\n let mut num = num as usize;\n let | BigMih | NORMAL | 2022-04-10T11:32:11.909191+00:00 | 2022-04-10T12:11:28.525991+00:00 | 101 | false | ```\nimpl Solution {\n pub fn largest_integer(num: i32) -> i32 {\n use std::collections::BinaryHeap;\n\n let mut num = num as usize;\n let mut evens_odds = [BinaryHeap::new(), BinaryHeap::new()];\n let mut digits = Vec::new();\n\n while num > 0 {\n let dig = num % 10;\n ... | 3 | 0 | ['Rust'] | 0 |
largest-number-after-digit-swaps-by-parity | ✅ C++ | Sort Even and Odd | c-sort-even-and-odd-by-chandanagrawal23-bx8r | \nclass Solution {\npublic:\n int largestInteger(int num) {\n string s = to_string(num);\n \n vector<int>odd,even;\n \n fo | chandanagrawal23 | NORMAL | 2022-04-10T04:12:13.559959+00:00 | 2022-04-10T04:14:49.765739+00:00 | 278 | false | ```\nclass Solution {\npublic:\n int largestInteger(int num) {\n string s = to_string(num);\n \n vector<int>odd,even;\n \n for(auto xt : s)\n {\n if((xt-\'0\')%2)\n odd.push_back(xt-\'0\');\n else\n even.push_back(xt-\'0\')... | 3 | 1 | ['C', 'Sorting'] | 1 |
largest-number-after-digit-swaps-by-parity | Python3 O(nlogn) Solution with explanation | python3-onlogn-solution-with-explanation-omgl | The idea here is to grab all the odd and even integers separately in their own lists. We then sort the odd and even lists in descending order. Finally, we ite | condor_code | NORMAL | 2022-04-10T04:01:33.239647+00:00 | 2022-04-10T04:06:43.117736+00:00 | 1,037 | false | The idea here is to grab all the odd and even integers separately in their own lists. We then sort the odd and even lists in descending order. Finally, we iterate over `num`. If the current digit in num is odd, we place the largest odd digit that remains in our odd list, and vice versa if the current digit is even.\... | 3 | 0 | ['Python'] | 1 |
largest-number-after-digit-swaps-by-parity | Collect the Digits into Odd and Even Heaps and Beat 100% | collect-the-digits-into-odd-and-even-hea-xqjr | IntuitionGather all even and odd digits and redistribute according to their magnitude.ApproachMake the input a string and iterate over the digit characters of t | HenryWan31 | NORMAL | 2025-02-02T07:35:32.629463+00:00 | 2025-02-02T07:35:32.629463+00:00 | 366 | false | # Intuition
Gather all even and odd digits and redistribute according to their magnitude.
# Approach
Make the input a string and iterate over the digit characters of the string. Along the way, collect the digits into heaps. Then redistribute the numbers from the most significant digit to the least significant digit. Y... | 2 | 0 | ['Python3'] | 2 |
largest-number-after-digit-swaps-by-parity | leetcodedaybyday - Beats 100% with C++ and Beats 100% with Python3 | leetcodedaybyday-beats-100-with-c-and-be-w94g | IntuitionThe problem requires rearranging the digits of a number to form the largest possible integer while maintaining the even/odd positions of the digits. An | tuanlong1106 | NORMAL | 2024-12-26T09:31:23.884293+00:00 | 2024-12-26T09:31:23.884293+00:00 | 572 | false | # Intuition
The problem requires rearranging the digits of a number to form the largest possible integer while maintaining the even/odd positions of the digits. An even digit can only replace another even digit, and an odd digit can only replace another odd digit. This ensures the resulting number preserves the parity ... | 2 | 0 | ['C++', 'Python3'] | 0 |
largest-number-after-digit-swaps-by-parity | 🔢 6. Priority Queue Solution !! || Simple Approach || Clean & Concise Code ! || C++ Code Reference | 6-priority-queue-solution-simple-approac-nfl4 | \n\ncpp [There You Go !!]\n\n int largestInteger(int n) {\n \n // Step 1\n vector<int> v;\n while(n){\n v.push_back(n% | Amanzm00 | NORMAL | 2024-07-12T06:28:03.394064+00:00 | 2024-07-12T06:28:03.394140+00:00 | 210 | false | \n\n```cpp [There You Go !!]\n\n int largestInteger(int n) {\n \n // Step 1\n vector<int> v;\n while(n){\n v.push_back(n%10);\n n=n/10;\n }\n // Step 2\n priority_queue<int> Odd,Even;\n for(auto& i:v)\n if(i&1) Odd.push(i);\n ... | 2 | 0 | ['Sorting', 'Heap (Priority Queue)', 'C++'] | 0 |
largest-number-after-digit-swaps-by-parity | BEATS 100% CPP SOLUTION WITH LINE-BY-LINE EXPLANATION | beats-100-cpp-solution-with-line-by-line-inhu | \n\n# Approach\n It converts the given integer num to a string s to work with its individual digits.\n\n It iterates through the digits of the string s using tw | Dominating_ | NORMAL | 2023-09-28T09:39:35.144319+00:00 | 2023-09-28T09:39:35.144350+00:00 | 402 | false | \n\n# Approach\n* It converts the given integer num to a string s to work with its individual digits.\n\n* It iterates through the digits of the string s using two nested loops. The outer loop (i) selects the current digit, and the inner loop (j) compares it with subsequent digits.\n\n* For each pair of digits (current... | 2 | 0 | ['C++'] | 0 |
largest-number-after-digit-swaps-by-parity | easy solution using priority queue | easy-solution-using-priority-queue-by-wt-rdx1 | Intuition\n Describe your first thoughts on how to solve this problem. \n maintain priority queues for even and odd numbers, store all the even and odd digits i | wtfcoder | NORMAL | 2023-06-17T15:12:11.011741+00:00 | 2023-06-17T15:12:11.011761+00:00 | 214 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n maintain priority queues for even and odd numbers, store all the even and odd digits in the number. traverse through the number and add the odd highest digit if it is odd , even highest digit if it is even. \n\n# Approach\n<!-- Describe ... | 2 | 0 | ['Heap (Priority Queue)', 'C++'] | 0 |
largest-number-after-digit-swaps-by-parity | ✅✔️Easy Implementation || Priority queue || 100% beat ✈️✈️✈️✈️✈️ | easy-implementation-priority-queue-100-b-bmiw | 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 | ajay_1134 | NORMAL | 2023-06-14T13:30:44.456765+00:00 | 2023-06-14T13:30:44.456782+00:00 | 211 | 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)$$ --... | 2 | 0 | ['Heap (Priority Queue)', 'C++'] | 0 |
largest-number-after-digit-swaps-by-parity | Simple Solution on Heap | simple-solution-on-heap-by-devill_05-xqth | 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 | devill_05 | NORMAL | 2023-05-21T10:33:33.151607+00:00 | 2023-05-21T10:33:33.151649+00:00 | 599 | 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)$$ --... | 2 | 0 | ['C++'] | 1 |
largest-number-after-digit-swaps-by-parity | 🚀🚀2231. Largest Number After Digit Swaps by Parity||EASY ||UNDERSTANDABLE||🚀🚀 | 2231-largest-number-after-digit-swaps-by-hjpo | Intuition\n\uD83D\uDCA1Find the largest number from the given number by swapping with partition.\n\n# Approach\n- seperate the number by single single digits an | saro_2003 | NORMAL | 2023-03-29T09:39:28.448497+00:00 | 2023-03-29T09:39:28.448547+00:00 | 2,878 | false | # Intuition\n\uD83D\uDCA1Find the largest number from the given number by swapping with partition.\n\n# Approach\n- seperate the number by single single digits and store it in the array.\n- then create two vector arrays and store odd and even seperately.\n- then sort the vector odd and even arrays in descending order .... | 2 | 0 | ['C', 'Sorting', 'Heap (Priority Queue)', 'C++', 'Java'] | 0 |
largest-number-after-digit-swaps-by-parity | using heap concept python3 | using-heap-concept-python3-by-mohammad_t-qq3w | 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-19T12:25:20.101345+00:00 | 2023-03-19T12:25:20.101380+00:00 | 892 | 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)$$ --... | 2 | 0 | ['Heap (Priority Queue)', 'Python3'] | 0 |
largest-number-after-digit-swaps-by-parity | max heap || easy | max-heap-easy-by-2stellon7-7pv9 | \n\n# Code\n\nclass Solution:\n def largestInteger(self, num: int) -> int:\n evenlist=[]\n oddlist=[]\n nums= [int(x) for x in str(num)] | 2stellon7 | NORMAL | 2022-12-27T18:44:10.843481+00:00 | 2022-12-27T18:44:10.843515+00:00 | 2,759 | false | \n\n# Code\n```\nclass Solution:\n def largestInteger(self, num: int) -> int:\n evenlist=[]\n oddlist=[]\n nums= [int(x) for x in str(num)]\n for i in nums:\n if i%2==0:\n evenlist.append(i)\n else:\n oddlist.append(i)\n even= [-x... | 2 | 0 | ['Python3'] | 0 |
largest-number-after-digit-swaps-by-parity | C++ Solution | c-solution-by-pranto1209-xwse | Code\n\nclass Solution {\npublic:\n int largestInteger(int num) {\n priority_queue<char> q0, q1;\n string s = to_string(num);\n int vis[ | pranto1209 | NORMAL | 2022-12-01T17:28:18.853163+00:00 | 2023-04-01T18:13:50.328995+00:00 | 1,152 | false | # Code\n```\nclass Solution {\npublic:\n int largestInteger(int num) {\n priority_queue<char> q0, q1;\n string s = to_string(num);\n int vis[15] = {};\n for(int i=0; i<s.size(); i++) {\n if((s[i]-\'0\') % 2) q1.push(s[i]), vis[i] = 1;\n else q0.push(s[i]);\n }... | 2 | 0 | ['C++'] | 0 |
largest-number-after-digit-swaps-by-parity | WORST SOLUTION | JAVA | BASIC | worst-solution-java-basic-by-prathmeshde-hk95 | Intuition\n Describe your first thoughts on how to solve this problem. \nused string and list to store the even and odd elements\n\n# Approach\n Describe your a | prathmeshdeshpande101 | NORMAL | 2022-11-25T11:01:15.908128+00:00 | 2022-11-25T11:01:15.908176+00:00 | 1,363 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nused string and list to store the even and odd elements\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nconverted num in string then added all values from string to even and odd list as per its type;\nthen sorted b... | 2 | 0 | ['Java'] | 0 |
largest-number-after-digit-swaps-by-parity | Largest Number After Digit Swaps by Parity Solution Java | largest-number-after-digit-swaps-by-pari-wsc1 | class Solution {\n public int largestInteger(int num) {\n final String s = String.valueOf(num);\n int ans = 0;\n // maxHeap[0] := odd digits\n // m | bhupendra786 | NORMAL | 2022-08-16T08:16:07.494147+00:00 | 2022-08-16T08:16:07.494193+00:00 | 239 | false | class Solution {\n public int largestInteger(int num) {\n final String s = String.valueOf(num);\n int ans = 0;\n // maxHeap[0] := odd digits\n // maxHeap[1] := even digits\n Queue<Integer>[] maxHeap = new Queue[2];\n\n for (int i = 0; i < 2; ++i)\n maxHeap[i] = new PriorityQueue<>(Comparator.rev... | 2 | 0 | ['Heap (Priority Queue)'] | 0 |
largest-number-after-digit-swaps-by-parity | Simple c++ solution | 100% faster | O(n) | simple-c-solution-100-faster-on-by-pravi-5fhh | Sorting is done for atmost 9 digits so its constant O(9 log9), for both time and space.\nOverall complexity: time - O(n), space - (1)\n\n1. Separate digits as p | pravin_ar | NORMAL | 2022-07-22T09:17:08.234489+00:00 | 2022-07-22T09:17:08.234534+00:00 | 217 | false | Sorting is done for atmost 9 digits so its constant O(9 log9), for both time and space.\nOverall complexity: time - O(n), space - (1)\n\n1. Separate digits as per parity.(odd/even)\n2. Sort individual odd & even array of digits\n3. Create num again using odd even array as per parity\n4. Note that we are using decending... | 2 | 0 | ['Sorting'] | 0 |
largest-number-after-digit-swaps-by-parity | C++ || 0ms || using 2 priority queues | c-0ms-using-2-priority-queues-by-shivavi-7ies | Hello folks!... Here our question is to find the largest possible number after swapping numbers with same parity.\n\nSuppose our number is 1234 (say num), \n\nH | ShivaVishwakarma | NORMAL | 2022-06-24T11:12:15.982701+00:00 | 2022-07-08T10:36:06.421114+00:00 | 215 | false | Hello folks!... Here our question is to find the **largest** possible number after swapping numbers with **same parity**.\n\nSuppose our number is **1234** (say **num**), \n\nHere we will make **2 max priority queues**, one is **odd priority queue** and other is **even priority queue**.\nNow, we will push all the even ... | 2 | 0 | ['Heap (Priority Queue)'] | 0 |
largest-number-after-digit-swaps-by-parity | Using two priority queue JAVA | using-two-priority-queue-java-by-user586-n2ak | \n\npublic int largestInteger(int num) {\n\t\tPriorityQueue<Integer> evenPq = new PriorityQueue<>();\n\t\tPriorityQueue<Integer> oddPq = new PriorityQueue<>();\ | user5869CS | NORMAL | 2022-05-29T15:57:38.876779+00:00 | 2022-05-29T15:57:38.876860+00:00 | 410 | false | ```\n\npublic int largestInteger(int num) {\n\t\tPriorityQueue<Integer> evenPq = new PriorityQueue<>();\n\t\tPriorityQueue<Integer> oddPq = new PriorityQueue<>();\n\t\tint ref = num;\n\t\twhile ( num > 0 ) {\n\t\t\tint right = num % 10;\n\t\t\tif ( right % 2 == 1 ) {\n\t\t\t\toddPq.offer(right);\n\t\t\t} else {\n\t\t\t... | 2 | 0 | ['Heap (Priority Queue)', 'Java'] | 0 |
largest-number-after-digit-swaps-by-parity | Wrong Testcase (Solved) | wrong-testcase-solved-by-alfinm01-8667 | Answer: Apparently the testcase isn\'t wrong, the misunderstanding has been explained by UserASh at https://leetcode.com/problems/largest-number-after-digit-swa | alfinm01 | NORMAL | 2022-04-23T16:15:02.344173+00:00 | 2022-06-19T13:19:20.794084+00:00 | 231 | false | ***Answer**: Apparently the testcase isn\'t wrong, the misunderstanding has been explained by UserASh at https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity/discuss/1975735/Wrong-Testcase/1367969*\n\n-----------------------------------------\n\n**Wrong Testcase:**\nThe expected answer should be `74... | 2 | 0 | ['Go'] | 2 |
largest-number-after-digit-swaps-by-parity | C++, Easy to understand, Faster than 100%, Priority Queue | c-easy-to-understand-faster-than-100-pri-fehq | ```\n int largestInteger(int num) {\n priority_queuepq1;\n priority_queuepq2;\n \n string s=to_string(num);\n int i=0;\n | msk318809 | NORMAL | 2022-04-17T07:02:12.630104+00:00 | 2022-06-25T18:41:15.901100+00:00 | 193 | false | ```\n int largestInteger(int num) {\n priority_queue<int>pq1;\n priority_queue<int>pq2;\n \n string s=to_string(num);\n int i=0;\n int n=s.size();\n while(n)\n { if(s[i]%2!=0)\n pq1.push(s[i]);\n else\n pq2.push(s[i]);\n ... | 2 | 0 | ['C', 'Heap (Priority Queue)'] | 0 |
largest-number-after-digit-swaps-by-parity | [Python3] 5 lines. Sort odd and even numbers | python3-5-lines-sort-odd-and-even-number-bpe6 | If the first number is an odd number, to make the total number biggest, we need to swap the biggest odd number to this place. If the first number is even number | yuanzhi247012 | NORMAL | 2022-04-13T01:41:59.839590+00:00 | 2022-04-13T10:00:52.999371+00:00 | 199 | false | If the first number is an odd number, to make the total number biggest, we need to swap the biggest odd number to this place. If the first number is even number, we swap the biggest even number to this place.\nFor the second number, if it is odd, we swap the 2nd biggest odd number to this place. If it is even, we swap ... | 2 | 0 | [] | 2 |
largest-number-after-digit-swaps-by-parity | C++ Simple Approach || Sorting || Easy | c-simple-approach-sorting-easy-by-yogesh-siq5 | \nclass Solution {\npublic:\n int largestInteger(int num) {\n string s=to_string(num);\n string a,b;\n for(char c:s){\n if(c%2==0 | Yogesh02 | NORMAL | 2022-04-11T14:56:16.561682+00:00 | 2022-04-11T14:56:16.561715+00:00 | 383 | false | ```\nclass Solution {\npublic:\n int largestInteger(int num) {\n string s=to_string(num);\n string a,b;\n for(char c:s){\n if(c%2==0){\n a+=c;\n }\n else{\n b+=c;\n }\n }\n sort(a.begin(),a.end(),greater<int>());\n so... | 2 | 0 | ['C', 'Sorting', 'C++'] | 0 |
largest-number-after-digit-swaps-by-parity | [JavaScript] Simple, Clean NlogN Sorting Solution | javascript-simple-clean-nlogn-sorting-so-hqxs | \n/*\n1. Seperate even and odd values into seperate arrays\n2. Sort both in ascending order (that way popping from the end will give max even or add number in O | YogiPaturu | NORMAL | 2022-04-10T14:53:23.488170+00:00 | 2022-04-10T14:53:23.488214+00:00 | 620 | false | ```\n/*\n1. Seperate even and odd values into seperate arrays\n2. Sort both in ascending order (that way popping from the end will give max even or add number in O(1) time)\n3. Loop through nums\n - If it\'s an even number, pop from the even array (i.e., the largest even number)\n - Otherwise, it\'s an odd number... | 2 | 0 | ['Sorting', 'JavaScript'] | 1 |
largest-number-after-digit-swaps-by-parity | C++ | | EASY TO UNDERSTAND | c-easy-to-understand-by-pratik263-mc0p | \n\nclass Solution {\npublic:\n int largestInteger(int num) {\n string s = to_string(num);\n int n = s.size();\n for(int i=0; i<n; i++){ | pratik263 | NORMAL | 2022-04-10T10:22:47.530461+00:00 | 2022-04-10T10:22:47.530489+00:00 | 62 | false | \n```\nclass Solution {\npublic:\n int largestInteger(int num) {\n string s = to_string(num);\n int n = s.size();\n for(int i=0; i<n; i++){\n for(int j=i+1; j<n; j++){\n int b = (s[j] - \'0\');\n int p = (s[i] - \'0\');\n if(p<b && ((p%2==0... | 2 | 0 | ['String', 'Sorting'] | 0 |
largest-number-after-digit-swaps-by-parity | simple c++ solution | simple-c-solution-by-crybaby_01-ij9v | \nint largestInteger(int num) {\n string s=to_string(num);\n int n=s.size();\n for(int i=0;i<n;i++){\n for(int j=i+1;j<n;j++){\n | Crybaby_01 | NORMAL | 2022-04-10T07:43:09.633966+00:00 | 2022-04-10T07:43:09.633998+00:00 | 69 | false | ```\nint largestInteger(int num) {\n string s=to_string(num);\n int n=s.size();\n for(int i=0;i<n;i++){\n for(int j=i+1;j<n;j++){\n if((s[i]-\'0\')%2==0&&(s[j]-\'0\')%2==0&&s[i]<s[j]) swap(s[i],s[j]); //both even\n else if((s[i]-\'0\')%2!=0&&(s[j]-\'0\')%2!... | 2 | 0 | ['String', 'C'] | 0 |
largest-number-after-digit-swaps-by-parity | ✔️ 2 solution approaches explained with logic and code || 8ms || 2ms || beats 100% | 2-solution-approaches-explained-with-log-jn6b | Solution 1 Idea : If swapping is allowed among odd numbers or even numbers, then why not construct a list of all odd numbers and even numbers and sort them in d | pg07codes | NORMAL | 2022-04-10T04:40:45.197424+00:00 | 2022-04-10T04:40:45.197453+00:00 | 263 | false | **Solution 1 Idea** : If swapping is allowed among odd numbers or even numbers, then why not construct a list of all odd numbers and even numbers and sort them in descending order. Now as we go through the input number, we check if the digit is odd, we get the best from odd, increment it. If the digit is even, we get t... | 2 | 0 | ['Java'] | 0 |
largest-number-after-digit-swaps-by-parity | Python heap | python-heap-by-nuoaleon-58s4 | \nclass Solution:\n def largestInteger(self, num: int) -> int:\n \n arr = list(str(num))\n \n odd = []\n even = []\n | Nuoaleon | NORMAL | 2022-04-10T04:29:53.592209+00:00 | 2022-04-10T04:30:36.174705+00:00 | 106 | false | ```\nclass Solution:\n def largestInteger(self, num: int) -> int:\n \n arr = list(str(num))\n \n odd = []\n even = []\n \n for ch in arr:\n if int(ch)%2 == 0:\n even.append(-int(ch))\n else:\n odd.append(-int(ch))\n ... | 2 | 0 | ['Greedy', 'Heap (Priority Queue)'] | 0 |
largest-number-after-digit-swaps-by-parity | Python | Priority Queue Solution | O(n log n) | python-priority-queue-solution-on-log-n-p37f8 | Approach :\n\n Store odd/even for each position.\n Use 2 priority queues to record the numbers of odd/even.\n* For each position, add the biggest number from od | phondani0 | NORMAL | 2022-04-10T04:29:16.133721+00:00 | 2022-04-10T04:36:05.002091+00:00 | 332 | false | **Approach :**\n\n* Store odd/even for each position.\n* Use 2 priority queues to record the numbers of odd/even.\n* For each position, add the biggest number from odd/even priority_queue to ans.\n```\nfrom queue import PriorityQueue\n\nclass Solution:\n def largestInteger(self, num: int) -> int:\n arr = []\n... | 2 | 0 | ['Heap (Priority Queue)', 'Python'] | 0 |
largest-number-after-digit-swaps-by-parity | C++ || Easy Brute Force || swap odd and even | c-easy-brute-force-swap-odd-and-even-by-ov40w | ```\nint largestInteger(int num) {\n string n=to_string(num);\n for(int i=0;in[i])\n {\n swap(n[i],n[j]);\n }\n | Aanchal20 | NORMAL | 2022-04-10T04:12:34.221884+00:00 | 2022-04-10T04:12:34.221916+00:00 | 65 | false | ```\nint largestInteger(int num) {\n string n=to_string(num);\n for(int i=0;i<n.size();i++)\n {\n for(int j=i+1;j<n.size();j++)\n {\n if(n[i]%2==0)\n {\n if(n[j]%2==0 && n[j]>n[i])\n {\n swap(n[i],n[j]);\n }\n }\n ... | 2 | 0 | [] | 0 |
largest-number-after-digit-swaps-by-parity | c++ | easy to understanding | c-easy-to-understanding-by-smit3901-r2ec | \n\tint largestInteger(int num) {\n string s = to_string(num);\n \n for(int i=0;i < s.size();i++)\n {\n for(int j=i+1;j < | smit3901 | NORMAL | 2022-04-10T04:01:57.030051+00:00 | 2022-04-10T04:01:57.030111+00:00 | 201 | false | \n\tint largestInteger(int num) {\n string s = to_string(num);\n \n for(int i=0;i < s.size();i++)\n {\n for(int j=i+1;j < s.size();j++)\n {\n if(s[i] < s[j] and ((s[i] - \'0\') % 2) == ((s[j] - \'0\') % 2))\n {\n char c =... | 2 | 0 | ['C'] | 1 |
largest-number-after-digit-swaps-by-parity | Largest Number After Digit Swaps by Parity | largest-number-after-digit-swaps-by-pari-itmk | IntuitionApproachComplexity
Time complexity:
O(n)
Space complexity:
O(n log n)Code | Vinil07 | NORMAL | 2025-03-30T17:44:17.620486+00:00 | 2025-03-30T17:44:17.620486+00:00 | 58 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(n ... | 1 | 0 | ['C++'] | 0 |
largest-number-after-digit-swaps-by-parity | Beats 100% in both Space Complexity and Time Complexity | beats-100-in-both-space-complexity-and-t-gwqt | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | eshaansingla | NORMAL | 2025-03-29T13:15:25.256092+00:00 | 2025-03-29T13:15:25.256092+00:00 | 19 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['Sorting', 'C++'] | 0 |
largest-number-after-digit-swaps-by-parity | Easy Java Solution | easy-java-solution-by-vermaanshul975-qkly | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | vermaanshul975 | NORMAL | 2025-03-27T14:57:45.839590+00:00 | 2025-03-27T14:57:45.839590+00:00 | 122 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['Java'] | 0 |
largest-number-after-digit-swaps-by-parity | Extract odd/even digits | extract-oddeven-digits-by-linda2024-ssh9 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | linda2024 | NORMAL | 2025-02-06T20:37:05.274553+00:00 | 2025-02-06T20:37:05.274553+00:00 | 15 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['C#'] | 0 |
largest-number-after-digit-swaps-by-parity | C++ O(log(n)) digit extraction | c-ologn-digit-extraction-by-vdrizzle-bxnu | IntuitionExtract the count of the digits from num O(log10(n)) Then built a new int based on the parity of digits in num from left to rightApproachFirst you ext | vdrizzle | NORMAL | 2025-01-30T06:23:35.762700+00:00 | 2025-01-30T06:23:35.762700+00:00 | 179 | false | # Intuition
Extract the count of the digits from `num` $$O(log_{10}(n))$$ Then built a new int based on the parity of digits in `num` from left to right
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
First you extract all the digits from `num` and track the count of their appearence, th... | 1 | 0 | ['C++'] | 0 |
largest-number-after-digit-swaps-by-parity | JavaScript | Simple intuitive approach | javascript-simple-intuitive-approach-by-7q0rr | Approach
Get all odd digits and sort them in increasing order.
Get all even digits and sort them in increasing order.
Go through all the digits: if it's even, t | dsitdikov | NORMAL | 2025-01-18T16:50:45.988751+00:00 | 2025-01-18T16:50:45.988751+00:00 | 38 | false | # Approach
1. Get all odd digits and sort them in increasing order.
2. Get all even digits and sort them in increasing order.
3. Go through all the digits: if it's even, take the last from the even stack and push to result; otherwise, from the odd stack.
# Complexity
- Time complexity: O(NlogN)
- Space complexity: O(... | 1 | 0 | ['JavaScript'] | 0 |
largest-number-after-digit-swaps-by-parity | Dart Solution | dart-solution-by-abiinavvv-gqfy | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | abiinavvv | NORMAL | 2025-01-04T08:57:27.031274+00:00 | 2025-01-04T08:57:27.031274+00:00 | 10 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['Sorting', 'Heap (Priority Queue)', 'Dart'] | 0 |
largest-number-after-digit-swaps-by-parity | 🟢🔴🟢 Beats 100.00%👏 Easiest Solution 🟢🔴🟢 | beats-10000-easiest-solution-by-develope-nr50 | \nclass Solution {\n int largestInteger(int num) {\n List<int> digits = [];\n while(num != 0){\n int r = num % 10;\n num ~/= 10;\n d | developerSajib88 | NORMAL | 2024-10-28T16:35:42.541219+00:00 | 2024-10-28T16:35:42.541241+00:00 | 116 | false | ```\nclass Solution {\n int largestInteger(int num) {\n List<int> digits = [];\n while(num != 0){\n int r = num % 10;\n num ~/= 10;\n digits.add(r);\n }\n digits = digits.reversed.toList();\n int largest = int.parse(digits.join());\n for(int i = 0; i < digits.length; i++){\n ... | 1 | 0 | ['C', 'Python', 'C++', 'Java', 'JavaScript', 'C#', 'Dart'] | 0 |
largest-number-after-digit-swaps-by-parity | Greedy Algo | greedy-algo-by-pasumarthi_ashik-23hf | 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 | PASUMARTHI_ASHIK | NORMAL | 2024-10-27T14:15:35.134637+00:00 | 2024-10-27T14:15:35.134667+00:00 | 16 | 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 | ['JavaScript'] | 0 |
largest-number-after-digit-swaps-by-parity | 0ms, beats 100% solution using 4 lists | 0ms-beats-100-solution-using-4-lists-by-lhdqd | Intuition\n Describe your first thoughts on how to solve this problem. \nEven digits share their space and odd digits share a different space. Within each of th | chichi666 | NORMAL | 2024-10-24T20:56:33.600251+00:00 | 2024-10-24T21:01:00.280726+00:00 | 128 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nEven digits share their space and odd digits share a different space. Within each of the 2 spaces, order the digits desc. Then reassemble all digits to get the result.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->... | 1 | 0 | ['Python3'] | 0 |
largest-number-after-digit-swaps-by-parity | Python 96.23%beat answer | python-9623beat-answer-by-army_y_wavy-a9r6 | \n# Solution Explanation: Sorting Even and Odd Digits Separately\nIn this solution, the goal is to rearrange the digits of a given integer num such that the fin | Army_Y_Wavy | NORMAL | 2024-08-23T02:19:32.310272+00:00 | 2024-08-23T02:23:17.086721+00:00 | 171 | false | \n# **Solution Explanation: Sorting Even and Odd Digits Separately**\nIn this solution, the goal is to rearrange the digits of a given integer num such that the final integer is the largest possible, while main... | 1 | 0 | ['Python', 'Python3'] | 0 |
largest-number-after-digit-swaps-by-parity | easy solution | easy-solution-by-arunkumarkandasamy-3jyz | 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 | arunkumarkandasamy | NORMAL | 2024-07-21T17:39:20.208523+00:00 | 2024-07-21T17:39:20.208547+00:00 | 805 | 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 |
largest-number-after-digit-swaps-by-parity | Using custom bubble sort for beautiful | using-custom-bubble-sort-for-beautiful-b-fo1m | Complexity\n- Time complexity: O(n^2) \n\n\n- Space complexity: O(1) \n\n# Code\npython\nclass Solution:\n def largestInteger(self, num: int) -> int:\n | tommy_dreck | NORMAL | 2024-06-17T10:22:14.633107+00:00 | 2024-06-17T10:22:14.633127+00:00 | 368 | false | # Complexity\n- Time complexity: $$O(n^2)$$ \n\n\n- Space complexity: $$O(1)$$ \n\n# Code\n```python\nclass Solution:\n def largestInteger(self, num: int) -> int:\n digits = []\n while num:\n digits.append(num % 10)\n num //= 10\n for i in range(len(digits) - 1, 0, -1):\n ... | 1 | 0 | ['Python3'] | 0 |
largest-number-after-digit-swaps-by-parity | The simplest approach using two heaps, beat 99% of python users | the-simplest-approach-using-two-heaps-be-zzwz | Intuition\n Describe your first thoughts on how to solve this problem. \nbuild max heap for odd digits and another one for even digits\nloop over original num\n | Ahmad-Amer | NORMAL | 2024-06-16T07:29:17.057915+00:00 | 2024-06-16T07:29:17.057951+00:00 | 70 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nbuild max heap for odd digits and another one for even digits\nloop over original num\nif digit is odd: append the maximum odd digit to the result, and remove it from the heap\nif digit is even: append the maximum even digit to the result... | 1 | 0 | ['Heap (Priority Queue)', 'Python3'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.