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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
permutations | JavaScript using DP | javascript-using-dp-by-loctn-iq76 | Here's the common backtracking solution for comparison:\n\nvar permute = function(nums) {\n const res = [];\n backtrack(nums, res);\n return res;\n};\n | loctn | NORMAL | 2017-02-25T14:36:13.313000+00:00 | 2018-09-17T02:55:01.360952+00:00 | 7,773 | false | Here's the common backtracking solution for comparison:\n```\nvar permute = function(nums) {\n const res = [];\n backtrack(nums, res);\n return res;\n};\n\nfunction backtrack(nums, res, n = 0) {\n if (n === nums.length - 1) {\n res.push(nums.slice(0));\n return;\n }\n for (let i = n; i <... | 26 | 1 | ['JavaScript'] | 3 |
permutations | Java | TC: O(N*N!) | SC: O(N) | Recursive Backtracking & Iterative Solutions | java-tc-onn-sc-on-recursive-backtracking-ncs4 | Recursive Backtracking\n\njava\n/**\n * Recursive Backtracking. In this solution passing the index of the nums that\n * needs to be set in the current recursion | NarutoBaryonMode | NORMAL | 2021-10-18T11:23:56.428444+00:00 | 2021-10-18T11:39:14.681959+00:00 | 2,438 | false | **Recursive Backtracking**\n\n```java\n/**\n * Recursive Backtracking. In this solution passing the index of the nums that\n * needs to be set in the current recursion.\n *\n * Time Complexity: O(N * N!). Number of permutations = P(N,N) = N!. Each\n * permutation takes O(N) to construct\n *\n * T(n) = n*T(n-1) + O(n)\n... | 25 | 0 | ['Backtracking', 'Recursion', 'Java'] | 1 |
permutations | Easy to understand solution in C++ | easy-to-understand-solution-in-c-by-pran-873h | \nclass Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n \n sort(nums.begin(),nums.end());\n vector<vector<int>> | pran_17 | NORMAL | 2021-07-02T09:24:09.948042+00:00 | 2021-07-02T09:24:09.948085+00:00 | 941 | false | ```\nclass Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n \n sort(nums.begin(),nums.end());\n vector<vector<int>> ans;\n ans.push_back(nums);\n while(next_permutation(nums.begin(),nums.end()))\n {\n ans.push_back(nums);\n }\n ... | 25 | 7 | [] | 0 |
permutations | My simple Javascript recursive solution | my-simple-javascript-recursive-solution-praf6 | var permute = function(nums) {\n let results = [];\n \n let permutations = (current, remaining) => {\n if(remaining.length <= 0) results.pus | jsonmartin | NORMAL | 2016-06-21T20:53:02+00:00 | 2018-09-11T18:55:48.963894+00:00 | 6,701 | false | var permute = function(nums) {\n let results = [];\n \n let permutations = (current, remaining) => {\n if(remaining.length <= 0) results.push(current.slice());\n else {\n for(let i = 0; i < remaining.length; i++) { // Loop through remaining elements\n current.push(rema... | 23 | 0 | ['JavaScript'] | 3 |
permutations | Simple Java Solution With Full Explanation || Simple Recursion || 1 ms faster than 93.44% | simple-java-solution-with-full-explanati-6vcf | \n\nclass Solution {\n public List<List<Integer>> permute(int[] nums) {\n return permutation(new ArrayList<>(),nums);\n }\n public List<List<Int | bits_manipulator | NORMAL | 2022-03-18T17:44:40.225215+00:00 | 2022-03-21T02:08:47.519392+00:00 | 1,618 | false | \n```\nclass Solution {\n public List<List<Integer>> permute(int[] nums) {\n return permutation(new ArrayList<>(),nums);\n }\n public List<List<Integer>> permutation(List<Integer> p,int[] up){\... | 22 | 0 | ['Recursion', 'Java'] | 3 |
permutations | C++ Backtracking | c-backtracking-by-paulariri-qt44 | \nclass Solution {\nprivate:\n vector<vector<int>> result;\n \npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n helper(nums, 0, (int | paulariri | NORMAL | 2020-08-09T03:02:26.854589+00:00 | 2020-08-09T03:02:26.854741+00:00 | 6,078 | false | ```\nclass Solution {\nprivate:\n vector<vector<int>> result;\n \npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n helper(nums, 0, (int)nums.size() - 1);\n \n return result;\n }\n \n void helper(vector<int> num_arr, int l, int r) {\n if (l == r){\n re... | 21 | 1 | ['Backtracking', 'Recursion', 'C', 'C++'] | 4 |
permutations | Clean JavaScript backtracking solution | clean-javascript-backtracking-solution-b-8xsj | js\nconst permute = (nums) => {\n const res = [];\n\n const go = (cur, rest) => {\n if (rest.length === 0) {\n res.push(cur);\n return;\n }\n\ | hongbo-miao | NORMAL | 2018-06-16T06:24:32.526250+00:00 | 2020-09-02T15:46:09.381045+00:00 | 2,494 | false | ```js\nconst permute = (nums) => {\n const res = [];\n\n const go = (cur, rest) => {\n if (rest.length === 0) {\n res.push(cur);\n return;\n }\n\n for (let i = 0; i < rest.length; i++) {\n // note if using array push and splice here, it will cause mutation\n go(\n [...cur, rest[i]]... | 20 | 0 | [] | 1 |
permutations | Very simple[C,C++,Java,python3 codes] Easy to understand Approach. | very-simpleccjavapython3-codes-easy-to-u-3a30 | Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is to generate all possible permutations of a given array of distinct integ | sriganesh777 | NORMAL | 2023-08-02T04:29:11.356524+00:00 | 2023-08-02T04:29:11.356560+00:00 | 1,039 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is to generate all possible permutations of a given array of distinct integers. A permutation is an arrangement of elements in a specific order. For example, given the array [1, 2, 3], the permutations are [[1, 2, 3], [1, 3, 2... | 19 | 0 | ['Backtracking', 'C', 'C++', 'Java', 'Python3'] | 0 |
permutations | 100% faster C++ Solution | Simple Solution | 100-faster-c-solution-simple-solution-by-2lzw | \nclass Solution {\nprivate:\n void solve(vector<int>& nums, vector<vector<int>>& ans, int index){\n if(index >= nums.size()){\n ans.push_b | code_shivam1 | NORMAL | 2022-01-10T18:33:23.160863+00:00 | 2022-01-10T18:33:23.160910+00:00 | 2,944 | false | ```\nclass Solution {\nprivate:\n void solve(vector<int>& nums, vector<vector<int>>& ans, int index){\n if(index >= nums.size()){\n ans.push_back(nums);\n return;\n }\n for(int j=index; j<nums.size(); j++){\n swap(nums[index], nums[j]);\n solve(nums, a... | 19 | 2 | ['Backtracking', 'Recursion', 'C', 'C++'] | 2 |
permutations | Easyway Explanation every step | easyway-explanation-every-step-by-paul_d-in3o | \n\ndfs(nums = [1, 2, 3] , path = [] , result = [] )\n|____ dfs(nums = [2, 3] , path = [1] , result = [] )\n| |___dfs(nums = [3] , path = [1, 2] , result = | paul_dream | NORMAL | 2020-10-17T07:58:03.697226+00:00 | 2020-10-17T07:58:03.697259+00:00 | 1,944 | false | ```\n\ndfs(nums = [1, 2, 3] , path = [] , result = [] )\n|____ dfs(nums = [2, 3] , path = [1] , result = [] )\n| |___dfs(nums = [3] , path = [1, 2] , result = [] )\n| | |___dfs(nums = [] , path = [1, 2, 3] , result = [[1, 2, 3]] ) # added a new permutation to the result\n| |___dfs(nums = [2] , path = ... | 19 | 1 | ['Backtracking', 'Python', 'Python3'] | 1 |
permutations | Easy to understand recursion - beats 97.38 | easy-to-understand-recursion-beats-9738-hby43 | \nclass Solution:\n def permute(self, nums: List[int]) -> List[List[int]]:\n n = len(nums)\n\t\t\n\t\t# Base conditions\n\t\t# If length is 0 or 1, th | sumeetsarkar | NORMAL | 2020-08-14T05:24:55.754861+00:00 | 2020-08-14T05:24:55.754890+00:00 | 1,846 | false | ```\nclass Solution:\n def permute(self, nums: List[int]) -> List[List[int]]:\n n = len(nums)\n\t\t\n\t\t# Base conditions\n\t\t# If length is 0 or 1, there is only 1 permutation\n if n in [0, 1]:\n return [nums]\n\t\t\n\t\t# If length is 2, then there are only two permutations\n\t\t# Exampl... | 19 | 0 | ['Python'] | 2 |
permutations | New approach: directly find the kth permutation (k = 1...n!) with a simple loop | new-approach-directly-find-the-kth-permu-g040 | Explanation\n\nThe general idea is the following (same as other solutions):\n\n 1. We know there are n! possible permutations for n elements.\n 2. Enumerate the | twisterrob | NORMAL | 2015-11-29T11:08:15+00:00 | 2018-08-11T13:46:56.665328+00:00 | 10,461 | false | # Explanation\n\nThe general idea is the following (same as other solutions):\n\n 1. We know there are `n!` possible permutations for `n` elements.\n 2. Enumerate them one by one\n\nMost solutions use the previous permutation to generate the next permutation or build it recursively.\nI had the idea to calculate the `k`... | 19 | 1 | ['Iterator', 'Java'] | 5 |
permutations | Easy Explanation || Short Code || Backtracking | easy-explanation-short-code-backtracking-64rh | Intuition\n Describe your first thoughts on how to solve this problem. \nThe code aims to generate all possible permutations of a given set of numbers.\n\n# App | HoneyJammer | NORMAL | 2023-08-02T03:12:00.061939+00:00 | 2023-08-02T05:18:30.921702+00:00 | 2,457 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe code aims to generate all possible permutations of a given set of numbers.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe code uses a recursive backtracking approach to generate all the permutations. It st... | 18 | 3 | ['Backtracking', 'Recursion', 'C++'] | 2 |
permutations | 🔥✅✅ Beat 98.64% | ✅ Full explanation with pictures ✅✅🔥 | beat-9864-full-explanation-with-pictures-axu0 | \n\n\n\n\n\n\n\n\n\n\n\n\npython []\nclass Solution(object):\n def permute(self, nums):\n def backtrack(start):\n if start == len(nums):\n | DevOgabek | NORMAL | 2024-03-10T09:12:44.907208+00:00 | 2024-03-10T09:14:26.576476+00:00 | 4,372 | false | \n\n[](https:/... | 17 | 0 | ['Array', 'Backtracking', 'Python', 'C++', 'Python3', 'JavaScript'] | 3 |
permutations | ✅Simple C++ |Using Backtracking and STL ✅ | simple-c-using-backtracking-and-stl-by-x-ee4d | Intuition\n Describe your first thoughts on how to solve this problem. \nSimply do swaping recusrively for every index and bactrack.\n# Approach\n Describe your | Xahoor72 | NORMAL | 2023-01-23T12:11:11.478698+00:00 | 2023-01-30T17:39:37.491880+00:00 | 3,069 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimply do swaping recusrively for every index and bactrack.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTwo approaches \n- Using Backtracking\n- Using STL function\n# Complexity\n- Time complexity:$$O(n!)$$\n<!--... | 16 | 0 | ['Math', 'Backtracking', 'C++'] | 0 |
permutations | ✅ [Solution] Swift: Permutations | solution-swift-permutations-by-asahiocea-4cyd | swift\nclass Solution {\n func permute(_ nums: [Int]) -> [[Int]] {\n let len = nums.count\n guard len >= 1 && len <= 6 else { return [] }\n | AsahiOcean | NORMAL | 2022-01-18T19:08:04.007334+00:00 | 2022-01-18T19:08:04.007367+00:00 | 1,910 | false | ```swift\nclass Solution {\n func permute(_ nums: [Int]) -> [[Int]] {\n let len = nums.count\n guard len >= 1 && len <= 6 else { return [] }\n \n var permutes = [[Int]](repeating: [], count: 1)\n \n for n in nums where n >= -10 && n <= 10 {\n var values: [[Int]] =... | 16 | 0 | ['Swift'] | 0 |
permutations | Golang - Beats 100% - Recursion & Explanation | golang-beats-100-recursion-explanation-b-tvmb | \n// To solve this problem we can use recursion.\n// If we think about it, a combination is valid when it has the same length of the input.\n// So, all we need | pug_jotaro_is_not_real | NORMAL | 2020-06-16T10:21:15.805184+00:00 | 2020-06-16T10:23:52.058011+00:00 | 2,231 | false | ```\n// To solve this problem we can use recursion.\n// If we think about it, a combination is valid when it has the same length of the input.\n// So, all we need to do is, have a concept of current combination (left) and left items (right)\n// that we need to analyse every time. We start with empty current combination... | 16 | 2 | ['Recursion', 'Go'] | 0 |
permutations | C# solution | c-solution-by-newbiecoder1-m360 | \n\nSolution 1\n\npublic class Solution {\n public IList<IList<int>> Permute(int[] nums) {\n \n List<IList<int>> res = new List<IList<int>>();\ | newbiecoder1 | NORMAL | 2020-04-19T05:51:42.315125+00:00 | 2020-04-19T06:18:45.324262+00:00 | 961 | false | \n\n**Solution 1**\n```\npublic class Solution {\n public IList<IList<int>> Permute(int[] nums) {\n \n List<IList<int>> res = new List<IList<int>>();\n Backtracking(nums, new List<int>(), res);\n return res;\n ... | 16 | 1 | [] | 1 |
permutations | ✅ Complex Backtracking Interview Prepare | List of Common Backtracking Problems | Beats 100% ✅ | complex-backtracking-interview-prepare-l-0pts | \n# Most common Backtracking Problems\nFrom the most to the least common (from GitHub/reddit):\n\n [17. Letter Combinations of a Phone Number] [51. N-Queens] \x | Piotr_Maminski | NORMAL | 2024-10-28T00:08:01.995182+00:00 | 2024-11-02T19:06:47.910249+00:00 | 1,863 | false | \n# Most common Backtracking Problems\nFrom the most to the least common (from GitHub/reddit):\n\n [[17. Letter Combinations of a Phone Number]](https://leetcode.com/problems/letter-combina... | 15 | 1 | ['Swift', 'C++', 'Java', 'Go', 'TypeScript', 'Python3', 'Rust', 'Ruby', 'JavaScript', 'C#'] | 0 |
permutations | clean short approach in python with intution explained | clean-short-approach-in-python-with-intu-e3uo | In recursion you want to think of an obvious solution, a solution which you\'re sure of, which is obvious. For ex: what will be the list of permutations of [1]? | bl4ckp4nther | NORMAL | 2021-01-26T15:29:06.540974+00:00 | 2021-01-26T17:06:40.867535+00:00 | 1,084 | false | In recursion you want to think of an obvious solution, a solution which you\'re sure of, which is obvious. For ex: what will be the list of permutations of [1]? obviously it\'ll be [1] only. This makes our base case.\n\nNext you need to think about how a normal typical person would go about solving it. Taking another e... | 15 | 0 | ['Array', 'Backtracking', 'Recursion', 'Python'] | 0 |
permutations | Easy and Simple C++ Approach ✅ | Beats 100%🔥🔥🔥 | easy-and-simple-c-approach-beats-100-by-iuigk | Approach\n1. Recursive Function Definition (solve):\n\n- The function solve is a private helper function that recursively generates permutations.\n- It takes th | AyushBansalCodes | NORMAL | 2024-08-08T07:04:01.228371+00:00 | 2024-08-08T07:04:01.228402+00:00 | 1,254 | false | # Approach\n1. Recursive Function Definition (`solve`):\n\n- The function `solve` is a private helper function that recursively generates permutations.\n- It takes three parameters:\n - `nums`: The current permutation of numbers being considered.\n - `index`: The current index in the array from which to start gen... | 14 | 0 | ['Backtracking', 'C++'] | 0 |
permutations | Mathematical proof that time complexity is O(e * n!) NOT O(n * n!) | mathematical-proof-that-time-complexity-0nvsn | I have seen a lot of answers here that simply state the time complexity is O(n*n!) but the justification isn\'t too well explained. Here I show a better approxi | amankhoza | NORMAL | 2022-05-26T00:43:54.564947+00:00 | 2022-05-26T00:53:18.124712+00:00 | 838 | false | I have seen a lot of answers here that simply state the time complexity is `O(n*n!)` but the justification isn\'t too well explained. Here I show a better approximation for the time complexity is actually `O(e*n!)`.\n\nFirst we must visualise the recursion tree (see other answers for recursive solution), the tree below... | 14 | 0 | [] | 2 |
permutations | Python BFS solution | python-bfs-solution-by-fabius11-8wkn | Python BFS solution\n\n```python\nfrom collections import deque\ndef permute(self, nums: List[int]) -> List[List[int]]: \n\tif len(nums) <= 1:\n\t\tretur | fabius11 | NORMAL | 2020-03-17T01:23:35.413589+00:00 | 2020-03-17T01:34:40.305196+00:00 | 3,076 | false | Python BFS solution\n\n```python\nfrom collections import deque\ndef permute(self, nums: List[int]) -> List[List[int]]: \n\tif len(nums) <= 1:\n\t\treturn [nums]\n\n\tans = []\n\tqueue = deque([([], nums)])\n\n\twhile queue:\n\t\tarr, options = queue.popleft()\n\n\t\tfor i in range(len(options)):\n\t\t\tnext_opt... | 14 | 1 | ['Breadth-First Search', 'Python', 'Python3'] | 1 |
permutations | Python iterative solution beat 99% | python-iterative-solution-beat-99-by-cha-nntl | The idea is to insert new num in the existing permutation to form new permutations.\n\nFor example, suppose we need to get all permutation of [1, 2, 3]. Assume | charleszhou327 | NORMAL | 2018-09-08T17:02:07.923443+00:00 | 2018-10-21T19:41:35.631990+00:00 | 2,194 | false | The idea is to insert new num in the existing permutation to form new permutations.\n\nFor example, suppose we need to get all permutation of `[1, 2, 3]`. Assume that we have got the permutation of `[1, 2]`, so `result = [[1, 2], [2, 1]]`. Then we could add 3 to each position of each element of result to get all permut... | 14 | 0 | [] | 4 |
permutations | Java solution easy to understand (backtracking) | java-solution-easy-to-understand-backtra-qcum | public class Solution {\n \n List> list;\n \n public List> permute(int[] nums) {\n \n list = new ArrayList<>();\n ArrayList per | arieeel | NORMAL | 2015-08-30T04:59:27+00:00 | 2015-08-30T04:59:27+00:00 | 7,920 | false | public class Solution {\n \n List<List<Integer>> list;\n \n public List<List<Integer>> permute(int[] nums) {\n \n list = new ArrayList<>();\n ArrayList<Integer> perm = new ArrayList<Integer>();\n backTrack(perm,0,nums);\n return list;\n }\n \n void backTrack (Arra... | 14 | 1 | [] | 5 |
permutations | Video solution | 2 approaches with intuition explained in detail | C++ | Backtracking | video-solution-2-approaches-with-intuiti-anzw | Video \n\nHey everyone, i have created video solution for this problem, (its in Hindi) i have solved this problem by backtracking using two methods \n\n- Using | _code_concepts_ | NORMAL | 2024-04-16T10:38:20.032336+00:00 | 2024-04-16T10:38:20.032356+00:00 | 1,076 | false | # Video \n\nHey everyone, i have created video solution for this problem, (its in Hindi) i have solved this problem by backtracking using two methods \n\n- Using visited array\n- Using swap method (more efficient and will clear all your doubts and confusion) \n\nif you have any consfusion on swap method ( when to swap ... | 13 | 1 | ['C++'] | 1 |
permutations | ✔️[C++ , Python3 , Java] Easy Explanation with Image (Backtracking Solution)✔️ | c-python3-java-easy-explanation-with-ima-x12d | Intuition\nSince the n is very small we could try all the permutations. \n\n# Approach\nTo solve this problem, we will use a recursive backtracking algorithm. T | upadhyayabhi0107 | NORMAL | 2023-08-02T03:33:26.756065+00:00 | 2023-08-02T03:38:04.805594+00:00 | 2,494 | false | # Intuition\nSince the n is very small we could try all the permutations. \n\n# Approach\nTo solve this problem, we will use a recursive backtracking algorithm. The main idea behind backtracking is to explore all possible combinations by trying out different choices and then undoing those choices if they lead to invali... | 13 | 0 | ['Backtracking', 'C++', 'Java', 'Python3'] | 1 |
permutations | Javascript DFS + Backtracking with heavy comments | javascript-dfs-backtracking-with-heavy-c-7iuo | \n/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nconst permute = (nums) => {\n // Backtracking\n const used = new Set(); // Keep track of w | tommymallis | NORMAL | 2022-09-06T21:47:03.594920+00:00 | 2022-09-09T04:12:42.922878+00:00 | 2,291 | false | ```\n/**\n * @param {number[]} nums\n * @return {number[][]}\n */\nconst permute = (nums) => {\n // Backtracking\n const used = new Set(); // Keep track of what we have used\n const path = []; // Current potiential answer array\n const res = []; // Result array to be returned\n \n const dfs = () => {\... | 13 | 0 | ['Backtracking', 'Depth-First Search', 'JavaScript'] | 3 |
permutations | ✔️ 100% Fastest Swift Solution | 100-fastest-swift-solution-by-sergeylesc-wlxo | \nclass Solution {\n\tfunc permute(_ nums: [Int]) -> [[Int]] {\n\t\tvar res: [[Int]] = []\n \n\n\t\tfunc recursion(_ list: [Int], _ rest: [Int]) -> Void | sergeyleschev | NORMAL | 2022-04-03T05:33:57.173218+00:00 | 2022-04-03T05:33:57.173366+00:00 | 1,125 | false | ```\nclass Solution {\n\tfunc permute(_ nums: [Int]) -> [[Int]] {\n\t\tvar res: [[Int]] = []\n \n\n\t\tfunc recursion(_ list: [Int], _ rest: [Int]) -> Void {\n for (i, item) in rest.enumerated() {\n\t\t\t\tvar list = list\n\t\t\t\tvar rest = rest\n\n\t\t\t\tlist.append(item)\n\t\t\t\trest.remove(at: i... | 13 | 0 | ['Swift'] | 0 |
permutations | Simple Python solution 68ms | simple-python-solution-68ms-by-dietpepsi-9wuk | def permute(self, nums):\n ans = [nums]\n for i in xrange(1, len(nums)):\n m = len(ans)\n for k in xrange(m):\n | dietpepsi | NORMAL | 2015-10-05T06:05:14+00:00 | 2018-10-22T10:49:35.907447+00:00 | 5,698 | false | def permute(self, nums):\n ans = [nums]\n for i in xrange(1, len(nums)):\n m = len(ans)\n for k in xrange(m):\n for j in xrange(i):\n ans.append(ans[k][:])\n ans[-1][j], ans[-1][i] = ans[-1][i], ans[-1][j]\n return ans\n... | 13 | 0 | ['Python'] | 0 |
permutations | 🚀 [VIDEO] Backtracking 100% - Unlocking Permutations | video-backtracking-100-unlocking-permuta-8u42 | Intuition\nUpon encountering this problem, I was immediately struck by its resemblance to a well-known puzzle: generating all possible permutations of a given s | vanAmsen | NORMAL | 2023-07-21T17:56:22.989161+00:00 | 2023-08-02T01:14:02.271729+00:00 | 1,927 | false | # Intuition\nUpon encountering this problem, I was immediately struck by its resemblance to a well-known puzzle: generating all possible permutations of a given sequence. It\'s like holding a Rubik\'s Cube of numbers and twisting it to discover every conceivable arrangement. With the challenge laid out, my mind gravita... | 12 | 0 | ['Swift', 'C++', 'Go', 'Python3', 'Rust'] | 2 |
permutations | Permutations Java Solution || 2 Approaches | permutations-java-solution-2-approaches-hsy1y | \n1. First Approach :- Generating all permutations\n\nTwo Extra Data Structure Required To generate permutation\n1. ArrayList<> subset //to store subset\n2. boo | palpradeep | NORMAL | 2022-11-03T08:39:38.728028+00:00 | 2022-11-06T12:53:45.579889+00:00 | 3,282 | false | ```\n1. First Approach :- Generating all permutations\n\nTwo Extra Data Structure Required To generate permutation\n1. ArrayList<> subset //to store subset\n2. boolean map[] //this map will tell us which element is pick or not picked at that time\n\n//Let\'s Understand\nExample :- [1,2,3]\n\nfor make permutation we c... | 12 | 0 | ['Backtracking', 'Recursion', 'Java'] | 3 |
permutations | 🍿 C++ || Easy-to-Understand with Diagram || 0 ms || Backtracking | c-easy-to-understand-with-diagram-0-ms-b-unzh | \n//image source gfg\n\n\t\tclass Solution {\n\t\tpublic:\n\t\t\tvoid helper(vector> &res , vector &nums,int i){\n\t\t\t\tif(i==nums.size()){\n\t\t\t\t\tres.pus | venom-xd | NORMAL | 2022-04-18T17:49:39.901957+00:00 | 2022-04-18T17:49:39.901993+00:00 | 1,126 | false | \n**//image source gfg**\n\n\t\tclass Solution {\n\t\tpublic:\n\t\t\tvoid helper(vector<vector<int>> &res , vector<int> &nums,int i){\n\t\t\t\tif(i==nums.size()){\n\t\t\t\t\tres.push_back(nums);\n\t\t\t\t\tretu... | 12 | 0 | ['Backtracking', 'Recursion', 'C', 'C++'] | 0 |
permutations | My C++ Solution Share | my-c-solution-share-by-jianhao-ubcj | It is obvious that N numbers has N! permutations .\n\nHere I assume an empty vector also has one permutation. It seems OJ didn't check the empty input case. Wel | jianhao | NORMAL | 2014-10-10T14:44:29+00:00 | 2014-10-10T14:44:29+00:00 | 6,168 | false | It is obvious that **N numbers has N! permutations** .\n\nHere I assume an empty vector also has one permutation. It seems OJ didn't check the empty input case. Well, it doesn't matter.\n\n\n class Solution {\n public:\n vector<vector<int> > permute(vector<int> &num) {\n // Add an empty vector a... | 12 | 0 | [] | 6 |
permutations | 2ms Java solution beats 93%, I think it could be optimized | 2ms-java-solution-beats-93-i-think-it-co-42cc | public class Solution {\n public List<List<Integer>> permute(int[] nums) {\n List<List<Integer>> result = new ArrayList<List<Integer>>();\n\t\tperm(re | andygogo | NORMAL | 2016-04-12T08:38:58+00:00 | 2016-04-12T08:38:58+00:00 | 3,571 | false | public class Solution {\n public List<List<Integer>> permute(int[] nums) {\n List<List<Integer>> result = new ArrayList<List<Integer>>();\n\t\tperm(result,nums,0,nums.length-1);\n\t\treturn result;\n }\n public static void perm(List<List<Integer>> result, int[] nums, int start, int end){\n\t\tif(sta... | 12 | 0 | ['Java'] | 1 |
permutations | easiest solution || c-plus-plus || easy to understand || only 4-5 lines code | easiest-solution-c-plus-plus-easy-to-und-0wm4 | 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 | youdontknow001 | NORMAL | 2022-11-24T07:58:30.105633+00:00 | 2022-11-24T07:58:30.105676+00:00 | 828 | 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)$$ --... | 11 | 0 | ['C++'] | 1 |
permutations | C++ clean code- two approaches with proper comments | c-clean-code-two-approaches-with-proper-9qk2r | Approach 1\n\nusing a freq array to store the number visited because it should not be included again in the answer\n\nclass Solution {\npublic:\n void solve( | geekie | NORMAL | 2021-09-14T12:47:54.661677+00:00 | 2021-09-14T17:05:12.107784+00:00 | 1,455 | false | Approach 1\n\nusing a freq array to store the number visited because it should not be included again in the answer\n```\nclass Solution {\npublic:\n void solve(vector<int>& nums,vector<int>&v,vector<vector<int>>&ans,int freq[])\n {\n if(v.size()==nums.size()){\n ans.push_back(v);\n re... | 11 | 1 | ['Backtracking', 'Recursion', 'C'] | 3 |
permutations | Simple python code without recursion | simple-python-code-without-recursion-by-eb34i | class Solution(object):\n def permute(self, nums):\n """\n :type nums: List[int]\n :rtype: List[List[int]]\n | holsety | NORMAL | 2016-05-24T02:52:17+00:00 | 2018-09-03T09:40:53.760034+00:00 | 4,767 | false | class Solution(object):\n def permute(self, nums):\n """\n :type nums: List[int]\n :rtype: List[List[int]]\n """\n def swap(i, j, nums):\n new_nums = list(nums)\n new_nums[i], new_nums[j] = new_nums[j], new_nums[i]\n ... | 11 | 0 | [] | 4 |
permutations | C++ || Bits approach + Recursion || Day 2 | c-bits-approach-recursion-day-2-by-chiik-6y9g | Code\n\nclass Solution {\npublic:\n vector<vector<int>>ans;\n void help(int mask,vector<int>&v,vector<int>&temp){\n if(mask==0){\n ans.p | CHIIKUU | NORMAL | 2023-08-02T06:52:35.257357+00:00 | 2023-08-02T06:52:35.257389+00:00 | 482 | false | # Code\n```\nclass Solution {\npublic:\n vector<vector<int>>ans;\n void help(int mask,vector<int>&v,vector<int>&temp){\n if(mask==0){\n ans.push_back(temp);\n return;\n }\n for(int i=0;i<v.size();i++){\n if(mask & (1<<i)){\n temp.push_back(v[i])... | 10 | 0 | ['C++'] | 4 |
permutations | 🔥 100% Backtracking / Recursive Approach - Unlocking Permutations | 100-backtracking-recursive-approach-unlo-2emz | Intuition\nThe problem requires generating all possible permutations of a given array of distinct integers. A clear and intuitive understanding of the recursive | phistellar | NORMAL | 2023-08-02T00:13:04.865905+00:00 | 2023-08-02T00:16:52.890840+00:00 | 3,365 | false | # Intuition\nThe problem requires generating all possible permutations of a given array of distinct integers. A clear and intuitive understanding of the recursive approach can be achieved by watching vanAmsen\'s video explanation, where the permutations are constructed by choosing one element at a time and recursively ... | 10 | 0 | ['C++', 'Java', 'Python3', 'JavaScript', 'C#'] | 1 |
permutations | Simple Python Solution. Beats 99%. with comments | simple-python-solution-beats-99-with-com-igdh | ```\nclass Solution(object):\n def permute(self, nums):\n \n res = []\n def dfs(path, num): # record the path and remaining numbers\n | cz2105 | NORMAL | 2022-07-18T00:09:36.050582+00:00 | 2022-07-18T00:09:36.050626+00:00 | 1,644 | false | ```\nclass Solution(object):\n def permute(self, nums):\n \n res = []\n def dfs(path, num): # record the path and remaining numbers\n if not num:\n res.append(path) # When finished iterating, append path to result\n return\n for i in range(l... | 10 | 0 | ['Python', 'Python3'] | 1 |
permutations | Java easy solution || Recursion and backtracking | java-easy-solution-recursion-and-backtra-ece4 | Code\n\njava\npublic List<List<Integer>> permute(int[] nums) {\n\tList<List<Integer>> list = new ArrayList<>();\n\tpermuteUtil(list, new ArrayList<>(), nums);\n | Chaitanya31612 | NORMAL | 2021-11-07T11:07:53.626714+00:00 | 2021-11-07T11:08:31.534938+00:00 | 1,663 | false | **Code**\n\n```java\npublic List<List<Integer>> permute(int[] nums) {\n\tList<List<Integer>> list = new ArrayList<>();\n\tpermuteUtil(list, new ArrayList<>(), nums);\n\treturn list;\n}\n\npublic void permuteUtil(List<List<Integer>> list, List<Integer> temp, int[] nums) {\n\t//base case\n\tif(temp.size() == nums.length)... | 10 | 0 | ['Backtracking', 'Recursion', 'Java'] | 2 |
permutations | Javascript BFS | javascript-bfs-by-erick_orozco-zcxj | Javascript Breath First Search. \n\nEach queue element will have two array: \n The first array is the current sequence we have constructed so far. \n The second | erick_orozco | NORMAL | 2021-09-29T02:58:52.192093+00:00 | 2021-09-29T02:59:33.189768+00:00 | 2,204 | false | Javascript Breath First Search. \n\nEach queue element will have two array: \n* The first array is the current sequence we have constructed so far. \n* The second array is the remaning numbers from nums. \n\nFor every element of the queue we add a new element for every remaning number. For example: \nif our nums = [1,2... | 10 | 0 | ['Breadth-First Search', 'JavaScript'] | 3 |
permutations | Easiest Golang solution (99% 4ms) | easiest-golang-solution-99-4ms-by-fpf999-xgld | \nfunc permute(nums []int) [][]int {\n answer := make([][]int, 0)\n aux(&answer, 0, nums)\n\treturn answer\n}\n\nfunc aux(answer *[][]int, idx int, nums [ | fpf999 | NORMAL | 2019-05-13T04:47:57.526253+00:00 | 2019-05-13T04:47:57.526284+00:00 | 1,055 | false | ```\nfunc permute(nums []int) [][]int {\n answer := make([][]int, 0)\n aux(&answer, 0, nums)\n\treturn answer\n}\n\nfunc aux(answer *[][]int, idx int, nums []int) {\n if idx == len(nums) {\n c := make([]int, len(nums))\n copy(c, nums)\n *answer = append(*answer, c)\n return\n }\n... | 10 | 0 | ['Recursion', 'Go'] | 1 |
permutations | JavaScript Solution | javascript-solution-by-tryck-7j7m | \nvar permute = function(nums) {\n let sol = [];\n if(nums.length < 1) {\n return [[]];\n } else if(nums.length == 1) {\n return [[nums[0 | tryck | NORMAL | 2019-04-16T22:01:53.692403+00:00 | 2019-04-16T22:01:53.692447+00:00 | 2,185 | false | ```\nvar permute = function(nums) {\n let sol = [];\n if(nums.length < 1) {\n return [[]];\n } else if(nums.length == 1) {\n return [[nums[0]]];\n } \n for(let i = 0; i < nums.length; i++) {\n let numsCopy = [...nums]; \n numsCopy.splice(i, 1); \n let rtnVal = permute(n... | 10 | 0 | [] | 2 |
permutations | 👏🏻 Python | DFS + BFS - 公瑾™ | python-dfs-bfs-gong-jin-tm-by-yuzhoujr-38u0 | 46. Permutations 此题收录在Github DFS ```python class Solution: def permute(self, nums): self.res = [] self.dfs(nums, []) return self.res | yuzhoujr | NORMAL | 2018-09-21T01:46:19.059526+00:00 | 2018-09-21T01:46:19.059605+00:00 | 1,400 | false | ### 46. Permutations
[此题收录在Github](https://github.com/yuzhoujr/leetcode/issues/33)
#### DFS
```python
class Solution:
def permute(self, nums):
self.res = []
self.dfs(nums, [])
return self.res
def dfs(self, nums, temp):
if len(nums) == len(temp):
self.res.append(... | 10 | 0 | [] | 0 |
permutations | Accepted Recursive Solution in Java | accepted-recursive-solution-in-java-by-b-9k6q | int len;\n boolean[] used;\n List<List<Integer>> result;\n List<Integer> temp;\n public List<List<Integer>> permute(int[] num) {\n len = num. | beyond2001 | NORMAL | 2015-04-03T15:30:44+00:00 | 2015-04-03T15:30:44+00:00 | 3,112 | false | int len;\n boolean[] used;\n List<List<Integer>> result;\n List<Integer> temp;\n public List<List<Integer>> permute(int[] num) {\n len = num.length;\n used = new boolean[len];\n result = new ArrayList<List<Integer>>();\n temp = new ArrayList<>();\n doPermute(num, 0);\n... | 10 | 0 | ['Probability and Statistics', 'Java'] | 0 |
permutations | Accepted as best in C | accepted-as-best-in-c-by-lhearen-0kcc | void swap(int* p, int* q)\n {\n int t = *p; *p = *q; *q = t;\n }\n void search(int* nums, int size, int*** arr, int* returnSize, int begin, int | lhearen | NORMAL | 2016-03-22T06:58:11+00:00 | 2016-03-22T06:58:11+00:00 | 3,154 | false | void swap(int* p, int* q)\n {\n int t = *p; *p = *q; *q = t;\n }\n void search(int* nums, int size, int*** arr, int* returnSize, int begin, int end)\n {\n if(begin == end)\n {\n (*returnSize)++;\n *arr = (int**)realloc(*arr, sizeof(int*)*(*returnSize));\n ... | 10 | 0 | [] | 3 |
permutations | ✅ One Line Solution | one-line-solution-by-mikposp-b88e | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)Code 1.1Time complexity: O(n!). Space complexity: O( | MikPosp | NORMAL | 2025-02-07T11:47:25.388341+00:00 | 2025-02-07T11:52:03.937472+00:00 | 1,932 | false | (Disclaimer: this is not an example to follow in a real project - it is written for fun and training mostly)
# Code 1.1
Time complexity: $$O(n!)$$. Space complexity: $$O(n!)$$.
```python3
class Solution:
def permute(self, a: List[int]) -> List[List[int]]:
return a and [[v]+p for v in a for p in self.permut... | 9 | 0 | ['Array', 'Backtracking', 'Recursion', 'Python', 'Python3'] | 0 |
permutations | c++ recurive solution || easy to understand | c-recurive-solution-easy-to-understand-b-ta5b | \n# Code\n\nclass Solution {\npublic:\n\n void findpermutation(vector<int>& nums, vector<vector<int>>&ans, vector<int>&ds,int freq[]){\n if(ds.size()= | harshil_sutariya | NORMAL | 2023-05-03T08:37:51.537314+00:00 | 2023-05-03T08:37:51.537349+00:00 | 4,437 | false | \n# Code\n```\nclass Solution {\npublic:\n\n void findpermutation(vector<int>& nums, vector<vector<int>>&ans, vector<int>&ds,int freq[]){\n if(ds.size()==nums.size()){\n ans.push_back(ds);\n return;\n }\n for(int i=0;i<nums.size(); i++){\n if(!freq[i]){\n ... | 9 | 0 | ['Recursion', 'C++'] | 1 |
permutations | [Java] [4 Approaches] Visuals + Time Complexity Analysis | java-4-approaches-visuals-time-complexit-gdkh | For Python implementation (AND/OR) a more detailed explanation and visuals -> checkout this post:\nhttps://leetcode.com/problems/permutations/discuss/993970/Pyt | Hieroglyphs | NORMAL | 2021-01-01T04:09:43.569721+00:00 | 2021-01-01T04:13:11.518798+00:00 | 951 | false | - **For Python implementation (AND/OR) a more detailed explanation and visuals -> checkout this post:**\nhttps://leetcode.com/problems/permutations/discuss/993970/Python-4-Approaches-%3A-Visuals-%2B-Time-Complexity-Analysis\n\n- **For JAVA implementation => scroll down**\n------------------------\n\n**Recursive with ba... | 9 | 0 | ['Backtracking', 'Depth-First Search', 'Breadth-First Search', 'Recursion', 'Iterator', 'Python'] | 2 |
permutations | Python Simple Solution EXPLAINED (video + code) (beginner) | python-simple-solution-explained-video-c-a5gn | \nhttps://www.youtube.com/watch?v=DBLUa6ErLKw\n\nclass Solution:\n def __init__(self):\n self.res = []\n \n def permute(self, nums: List[int | spec_he123 | NORMAL | 2020-09-19T19:48:51.350741+00:00 | 2020-09-19T19:48:51.350774+00:00 | 1,268 | false | [](https://www.youtube.com/watch?v=DBLUa6ErLKw)\nhttps://www.youtube.com/watch?v=DBLUa6ErLKw\n```\nclass Solution:\n def __init__(self):\n self.res = []\n \n def permute(self, nums: List[int]) -> List[List[int]]:\n self.backtrack(nums, [])\n return self.res\n \n def backtrack(sel... | 9 | 0 | ['Backtracking', 'Python3'] | 1 |
permutations | java solution . BACKTRACK.!! REMOVE the LAST ELEMENT!!! | java-solution-backtrack-remove-the-last-1qn0z | Please upvote if helpFul!!\n\nclass Solution {\n //[1,2,3]\n public List<List<Integer>> permute(int[] nums) {\n List<List<Integer>> list = new Arra | kunal3322 | NORMAL | 2020-08-13T21:20:55.571078+00:00 | 2020-08-13T21:22:04.024796+00:00 | 873 | false | * **Please upvote if helpFul!!**\n```\nclass Solution {\n //[1,2,3]\n public List<List<Integer>> permute(int[] nums) {\n List<List<Integer>> list = new ArrayList<>();\n backtrack(list, new ArrayList<>(), nums);\n return list;\n }\n\n private void backtrack(List<List<Integer>> resultList... | 9 | 2 | ['Backtracking', 'Java'] | 1 |
permutations | [C++] No Recursion! 8 Lines, STL (no Explanation Needed) | c-no-recursion-8-lines-stl-no-explanatio-8kd0 | ```\nclass Solution {\npublic:\n \n vector> permute(vector& nums) \n {\n vector> ourResult;\n vector singleIter = nums;\n\t\tourResult.pu | leetcodegrindtt | NORMAL | 2020-01-20T16:10:43.392675+00:00 | 2020-01-20T16:11:01.649483+00:00 | 2,077 | false | ```\nclass Solution {\npublic:\n \n vector<vector<int>> permute(vector<int>& nums) \n {\n vector<vector<int>> ourResult;\n vector<int> singleIter = nums;\n\t\tourResult.push_back(singleIter);\n next_permutation(singleIter.begin(), singleIter.end());\n while (singleIter != nums)\n ... | 9 | 3 | ['C', 'C++'] | 2 |
permutations | Java Backtracking Solution | java-backtracking-solution-by-laonawuli-jugw | public class Solution {\n public List<List<Integer>> permute(int[] nums) {\n List<List<Integer>> lists = new ArrayList<>();\n if (nums == null | laonawuli | NORMAL | 2015-11-30T20:31:48+00:00 | 2015-11-30T20:31:48+00:00 | 2,884 | false | public class Solution {\n public List<List<Integer>> permute(int[] nums) {\n List<List<Integer>> lists = new ArrayList<>();\n if (nums == null || nums.length == 0) {\n return lists;\n }\n\n dfs(nums, lists, new ArrayList<Integer>());\n return lists;\n }\n\n pri... | 9 | 0 | [] | 1 |
permutations | 📸 The Permutation Party: When Numbers Can't Stop Taking Selfies! | the-permutation-party-when-numbers-cant-db6ca | 🎢 Welcome to the Permutation Party! 🎉Imagine you're at a party where your friends (the numbers) want to take all possible group selfies. Each time they line up | trivickram_1476 | NORMAL | 2025-03-29T05:03:40.670244+00:00 | 2025-03-29T05:08:16.734994+00:00 | 715 | false | # 🎢 Welcome to the Permutation Party! 🎉
Imagine you're at a party where your friends (the numbers) want to take all possible group selfies. Each time they line up differently, they click a pic! 📸
**Step 1:** The Solo Shot
If there’s only one friend (number) at the party, the only option is to click a solo pic. Done... | 8 | 2 | ['Array', 'Backtracking', 'Java', 'Python3'] | 3 |
permutations | 100% beats|| CPP | 100-beats-cpp-by-sunny7549-k86t | Intuition :The problem requires generating all permutations of a given array of distinct integers.
Since the order of elements matters in permutations, backtrac | Sunny7549-_ | NORMAL | 2025-03-19T15:02:23.903654+00:00 | 2025-03-19T15:02:23.903654+00:00 | 695 | false | # Intuition :
The problem requires generating all permutations of a given array of distinct integers.
Since the order of elements matters in permutations, backtracking is an ideal approach to explore all possible arrangements.
We can build permutations incrementally by trying each element, marking it as used, and cont... | 8 | 3 | ['C++'] | 0 |
permutations | Python Solution | python-solution-by-a_bs-1rba | Permutation Intuition, Approach, and Complexity\n\nIntuition:\n\nImagine you have a box of distinct balls (the numbers). You want to find all the possible ways | 20250406.A_BS | NORMAL | 2024-05-24T18:28:22.228784+00:00 | 2024-05-24T18:28:22.228809+00:00 | 641 | false | ## Permutation Intuition, Approach, and Complexity\n\n**Intuition:**\n\nImagine you have a box of distinct balls (the numbers). You want to find all the possible ways to arrange them in a line (permutation). We can think of this as building the arrangements step-by-step. At each step, we choose a ball from the box (rem... | 8 | 0 | ['Python3'] | 2 |
permutations | ✅✅C++ Easy Recursive and Backtracking Solution || Heavy commented | c-easy-recursive-and-backtracking-soluti-d7eg | \u2705\u2705C++ Easy Recursive and Backtracking Solution\n# Please Upvote as it really motivates me\n\n\nclass Solution {\npublic:\n void rec(int idx,vector< | Conquistador17 | NORMAL | 2023-08-02T05:03:59.689729+00:00 | 2023-08-02T05:03:59.689761+00:00 | 608 | false | ## **\u2705\u2705C++ Easy Recursive and Backtracking Solution**\n# **Please Upvote as it really motivates me**\n\n```\nclass Solution {\npublic:\n void rec(int idx,vector<int>&nums,vector<vector<int>>&ans){\n //if our index reached nums.size() then we will and the nums in ans and return\n if(idx==nums.... | 8 | 0 | ['Backtracking', 'Recursion', 'C', 'C++'] | 0 |
permutations | Backtracking || O(n!) Time and O(n!) Space || Easiest Beginner Friendly Sol | backtracking-on-time-and-on-space-easies-lfl5 | NOTE - PLEASE READ INTUITION AND APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.\n\n# Intuitio | singhabhinash | NORMAL | 2023-05-02T04:34:15.873295+00:00 | 2023-05-02T04:34:15.873336+00:00 | 1,204 | false | **NOTE - PLEASE READ INTUITION AND APPROACH FIRST THEN SEE THE CODE. YOU WILL DEFINITELY UNDERSTAND THE CODE LINE BY LINE AFTER SEEING THE APPROACH.**\n\n# Intuition of this Problem :\n\n\n*The problem of g... | 8 | 0 | ['Array', 'Backtracking', 'C++'] | 0 |
permutations | Java - Explained - Multiple Approaches | java-explained-multiple-approaches-by-ja-587n | 1. Using extra space\n\nCreate two containers \n\t- First is for candidates for next permutations\n\t- Second is for storing current permutation\n\nNow let\'s c | jainakshat425 | NORMAL | 2022-04-29T04:09:19.183563+00:00 | 2022-04-29T04:09:19.183614+00:00 | 477 | false | **1. Using extra space**\n\nCreate two containers \n\t- First is for candidates for next permutations\n\t- Second is for storing current permutation\n\nNow let\'s consider we\'ve to generate all the permutations for [1,2,3]\n\nInitially we\'ll have - \nCandidates = [1,2,3] \nPermutation = []\n\nNow we\'ll call a ... | 8 | 0 | ['Java'] | 0 |
permutations | Simple and easy to understand C++ using recursion [98% faster, 100% memory] | simple-and-easy-to-understand-c-using-re-qb2u | \nclass Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n vector<vector<int>> results;\n generatePermutations(0, &nums, | shlom | NORMAL | 2020-03-01T17:15:02.515691+00:00 | 2020-03-01T17:15:02.515726+00:00 | 1,155 | false | ```\nclass Solution {\npublic:\n vector<vector<int>> permute(vector<int>& nums) {\n vector<vector<int>> results;\n generatePermutations(0, &nums, &results);\n return results;\n }\nprivate:\n void generatePermutations(int i, vector<int>* nums_ptr, vector<vector<int>>* results) {\n au... | 8 | 0 | ['Recursion', 'C++'] | 2 |
permutations | Javascript solution +98% | javascript-solution-98-by-xueccc-f8hd | \nvar permute = function(nums) {\n\n let permutations = []\n \n let findPermutations = function(visited = new Set(), currPerm = []) {\n if (curr | xueccc | NORMAL | 2019-09-24T02:26:13.489776+00:00 | 2019-09-24T04:23:40.413212+00:00 | 2,240 | false | ```\nvar permute = function(nums) {\n\n let permutations = []\n \n let findPermutations = function(visited = new Set(), currPerm = []) {\n if (currPerm.length === nums.length) {\n permutations.push(currPerm)\n return\n }\n for (let i = 0; i < nums.length; i++) {\n ... | 8 | 0 | ['JavaScript'] | 5 |
permutations | Easy solution for Kotlin | easy-solution-for-kotlin-by-vila_teissie-5p3i | \nclass Solution {\n private val result: MutableList<List<Int>> = mutableListOf()\n\n fun permute(nums: IntArray): List<List<Int>> {\n permuteAux(m | vila_teissiere | NORMAL | 2019-03-03T06:58:44.381628+00:00 | 2019-03-03T06:58:44.381709+00:00 | 301 | false | ```\nclass Solution {\n private val result: MutableList<List<Int>> = mutableListOf()\n\n fun permute(nums: IntArray): List<List<Int>> {\n permuteAux(mutableListOf(), nums.toList())\n return result\n }\n\n private fun permuteAux(added: List<Int>, left: List<Int>) {\n if (left.isEmpty()) ... | 8 | 0 | [] | 3 |
permutations | Share My C++ backtracksolution | share-my-c-backtracksolution-by-allenyic-8qhz | \n class Solution {\n public:\n vector > permute(vector &num) {\n \tvector > res; // result\n \tvector flags( num.size(), false); | allenyick | NORMAL | 2015-01-18T04:18:47+00:00 | 2015-01-18T04:18:47+00:00 | 2,132 | false | \n class Solution {\n public:\n vector<vector<int> > permute(vector<int> &num) {\n \tvector<vector<int> > res; // result\n \tvector<bool> flags( num.size(), false); // bool, whether num[i] is choosed\n \tvector<int> path; // num have been choosed\n \tbacktrack(num, res,... | 8 | 0 | [] | 1 |
number-of-rectangles-that-can-form-the-largest-square | [Java/Python 3] 1 pass O(n) time O(1) space. | javapython-3-1-pass-on-time-o1-space-by-dzz5q | There are 3 cases after initializing the counter cnt and the max side mx as 0:\nThe square side\n1) greater than mx, reset cnt to 1 and update mx;\n2) == mx, i | rock | NORMAL | 2021-01-17T04:02:26.468401+00:00 | 2021-01-17T08:11:37.683699+00:00 | 5,539 | false | There are 3 cases after initializing the counter `cnt` and the max side `mx` as `0`:\nThe square side\n1) greater than `mx`, reset `cnt` to `1` and update `mx`;\n2) == `mx`, increase `cnt` by 1;\n3) less than `mx`, ignore it.\n\n\n```java\n public int countGoodRectangles(int[][] rectangles) {\n int cnt = 0, ... | 88 | 7 | [] | 11 |
number-of-rectangles-that-can-form-the-largest-square | JAVA || C++ || O(n) || FASTER THAN 100% || WITH MAP || WITHOUT MAP | java-c-on-faster-than-100-with-map-witho-rweu | C++\n\n1.using map\n\nRuntime: 36 ms, faster than 100.00% of C++ online submissions \nMemory Usage: 20.2 MB, less than 100.00% of C++ online submissions\n\n\ncl | rajat_gupta_ | NORMAL | 2021-01-17T05:58:27.348753+00:00 | 2021-01-17T06:33:43.658143+00:00 | 2,978 | false | **C++**\n\n**1.using map**\n\n**Runtime: 36 ms, faster than 100.00% of C++ online submissions \nMemory Usage: 20.2 MB, less than 100.00% of C++ online submissions**\n\n```\nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n unordered_map<int,int> map;\n for(vector<... | 26 | 3 | ['C', 'C++', 'Java'] | 6 |
number-of-rectangles-that-can-form-the-largest-square | ✅C++ solution with sorting! | c-solution-with-sorting-by-dhruba-datta-lm0z | If you\u2019re interested in coding you can join my Discord Server, link in the comment section. Also if you find any mistakes please let me know. Thank you!\u2 | dhruba-datta | NORMAL | 2021-10-21T06:51:13.579455+00:00 | 2022-04-14T19:15:17.588044+00:00 | 1,750 | false | > **If you\u2019re interested in coding you can join my Discord Server, link in the comment section. Also if you find any mistakes please let me know. Thank you!\u2764\uFE0F**\n> \n\n---\n## Code:\n\n```\nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n int count=0;\n ... | 25 | 0 | ['C', 'C++'] | 4 |
number-of-rectangles-that-can-form-the-largest-square | [JAVA] easy and %100 solution | java-easy-and-100-solution-by-zeldox-cddj | if you like it pls upp vote\n\nJAVA\n\n\nclass Solution {\n public int countGoodRectangles(int[][] rectangles) {\n int max = 0;\n int res = 0;\ | zeldox | NORMAL | 2021-02-07T14:36:12.453508+00:00 | 2021-02-07T14:36:12.453537+00:00 | 1,116 | false | if you like it pls upp vote\n\nJAVA\n\n```\nclass Solution {\n public int countGoodRectangles(int[][] rectangles) {\n int max = 0;\n int res = 0;\n for(int i = 0;i< rectangles.length;i++){\n int key = Math.min(rectangles[i][0],rectangles[i][1]);\n if(key > max){\n ... | 20 | 1 | ['Java'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | Python - Runtime O(N) and O(1) space [ACCEPTED] | python-runtime-on-and-o1-space-accepted-xyqzq | This can be done just by tracking the max length and its count.\n\n```\ndef countGoodRectangles(rectangles):\n\tmax_len = float(\'-inf\')\n\tcount = 0\n\tfor it | jankit | NORMAL | 2021-01-17T12:51:18.817995+00:00 | 2021-01-17T13:49:13.189560+00:00 | 1,944 | false | This can be done just by tracking the max length and its count.\n\n```\ndef countGoodRectangles(rectangles):\n\tmax_len = float(\'-inf\')\n\tcount = 0\n\tfor item in rectangles:\n\t\tmin_len = min(item)\n\t\tif min_len == max_len:\n\t\t\tcount += 1\n\t\telif min_len > max_len:\n\t\t\tmax_len = min_len\n\t\t\tcount = 1\... | 20 | 0 | ['Python3'] | 6 |
number-of-rectangles-that-can-form-the-largest-square | c++ solution || O(n) | c-solution-on-by-yash_pal2907-b73p | \nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n unordered_map<int,int> maxsquarelen;\n int maxlen=IN | yash_pal2907 | NORMAL | 2021-01-17T05:11:40.971541+00:00 | 2021-01-17T05:11:40.971576+00:00 | 1,451 | false | ```\nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n unordered_map<int,int> maxsquarelen;\n int maxlen=INT_MIN;\n for(auto rectangle : rectangles){\n maxsquarelen[min(rectangle[0],rectangle[1])]++;\n maxlen = max(maxlen,min(rectangle... | 11 | 1 | ['C'] | 1 |
number-of-rectangles-that-can-form-the-largest-square | Python easier solution with explanation (dictionary) | python-easier-solution-with-explanation-h2gi0 | Explanation:\nTo get maximum square from rectangle we get the minimum from width and height. By dictionary we count all squares, and the value of the biggest | it_bilim | NORMAL | 2021-01-17T06:12:18.570237+00:00 | 2021-01-17T06:12:18.570290+00:00 | 878 | false | **Explanation:**\nTo get `maximum square` from rectangle we get the minimum from `width` and `height`. By dictionary we count `all squares`, and the `value` of `the biggest square`.\n\n```\ndef countGoodRectangles(self, rectangles):\n t = {}\n for r in rectangles:\n p = min(r) # get the mini... | 10 | 5 | ['Python', 'Python3'] | 1 |
number-of-rectangles-that-can-form-the-largest-square | C++ 32 ms | c-32-ms-by-eridanoy-jr4f | \nclass Solution {\npublic:\n int countGoodRectangles(const vector<vector<int>>& rectangles) {\n \n int side=0, maxLen=0, count=0;\n \n | eridanoy | NORMAL | 2021-01-20T20:25:03.168981+00:00 | 2021-01-20T20:25:03.169013+00:00 | 674 | false | ```\nclass Solution {\npublic:\n int countGoodRectangles(const vector<vector<int>>& rectangles) {\n \n int side=0, maxLen=0, count=0;\n \n for(const auto& i:rectangles) {\n \n side=min(i[0],i[1]);\n \n if(maxLen<side) {\n maxLen=s... | 9 | 0 | ['C'] | 1 |
number-of-rectangles-that-can-form-the-largest-square | Python 2 liner solution with explanation | python-2-liner-solution-with-explanation-c712 | \n######################################################\n\n# Runtime: 168ms - 100.00%\n# Memory: 14.8MB - 73.29%\n\n################################ | saisasank25 | NORMAL | 2022-01-15T07:46:25.332888+00:00 | 2022-01-15T07:46:25.332935+00:00 | 563 | false | ```\n######################################################\n\n# Runtime: 168ms - 100.00%\n# Memory: 14.8MB - 73.29%\n\n######################################################\n\nclass Solution:\n def countGoodRectangles(self, rectangles: List[List[int]]) -> int:\n # len_arr is a list where len_arr[... | 8 | 0 | ['Python'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | Simple and effective Javascript Solution | simple-and-effective-javascript-solution-5bgf | \nvar countGoodRectangles = function(rectangles) {\n let max = 0;\n let count = 0;\n \n for(let i = 0; i < rectangles.length; i++) {\n let mi | kosbay12 | NORMAL | 2021-03-28T07:42:23.071145+00:00 | 2021-03-28T07:42:23.071232+00:00 | 592 | false | ```\nvar countGoodRectangles = function(rectangles) {\n let max = 0;\n let count = 0;\n \n for(let i = 0; i < rectangles.length; i++) {\n let minSide = Math.min(rectangles[i][0], rectangles[i][1])\n \n if(minSide > max) {\n count = 0\n max = minSide\n } \n ... | 6 | 0 | ['JavaScript'] | 2 |
number-of-rectangles-that-can-form-the-largest-square | Easiest C++ Solution without Sorting ✅ | easiest-c-solution-without-sorting-by-_s-nq5l | Intuition\nThe code first calculates the largest square that can be cut from each rectangle by taking the minimum of the rectangle\'s length and width. It then | _sxrthakk | NORMAL | 2024-08-02T10:47:05.920777+00:00 | 2024-08-02T10:47:05.920809+00:00 | 164 | false | # Intuition\nThe code first calculates the largest square that can be cut from each rectangle by taking the minimum of the rectangle\'s length and width. It then uses an unordered map to count how many times each square size appears. The code then iterates through the map to find the maximum square size (a) and stores ... | 5 | 0 | ['Array', 'Hash Table', 'C++'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | solution | solution-by-vibishraj-rlaa | 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 | Vibishraj | NORMAL | 2024-07-10T16:44:37.339317+00:00 | 2024-07-10T16:44:37.339353+00:00 | 32 | 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)$$ --... | 5 | 0 | ['Java'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | Java Simple Solution 1 ms - 100% beats | java-simple-solution-1-ms-100-beats-by-a-dyls | Approach\nYou first have to create an array called "sides" to store the side lengths of each rectangle. Then, you iterate through the given "rectangles" array a | akobirswe | NORMAL | 2023-05-24T16:09:36.324774+00:00 | 2023-05-24T16:09:36.324809+00:00 | 406 | false | # Approach\nYou first have to create an array called "sides" to store the side lengths of each rectangle. Then, you iterate through the given "rectangles" array and compare the length and width of each rectangle. If the length is smaller than the width, you assign the length to the corresponding index in the "sides" ar... | 5 | 0 | ['Array', 'Java'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | C++ solution || easy to understand! | c-solution-easy-to-understand-by-mohiter-66em | ```\nclass Solution {\npublic:\n int countGoodRectangles(vector>& rect) {\n vectorans;\n int c=0;\n for(int i=0;i<rect.size();i++){\n | mohiteravi348 | NORMAL | 2022-12-03T11:33:45.951005+00:00 | 2022-12-03T11:33:45.951032+00:00 | 390 | false | ```\nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rect) {\n vector<int>ans;\n int c=0;\n for(int i=0;i<rect.size();i++){\n \n ans.push_back(*min_element(rect[i].begin(),rect[i].end()));\n \n \n }\n \n int m=*max_eleme... | 5 | 0 | ['C'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | simple O(n) using HashMap | simple-on-using-hashmap-by-armageddon203-d4fo | \nvar countGoodRectangles = function (rectangles) {\n let map = new Map(),max=0;\n rectangles.forEach(el => {\n max=Math.max(max,Math.min(el[0], el[1]));\n | armageddon2033 | NORMAL | 2021-01-17T12:02:35.756364+00:00 | 2021-01-17T12:02:35.756394+00:00 | 394 | false | ```\nvar countGoodRectangles = function (rectangles) {\n let map = new Map(),max=0;\n rectangles.forEach(el => {\n max=Math.max(max,Math.min(el[0], el[1]));\n map.set(Math.min(el[0], el[1]), map.get(Math.min(el[0], el[1])) + 1 || 1);\n });\n return map.get(max);\n};\n``` | 5 | 0 | ['JavaScript'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | C++ code in linear time || Faster then others | c-code-in-linear-time-faster-then-others-zrbl | \n\n# Complexity\n- Time complexity:O(N)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n | Shristha | NORMAL | 2023-01-10T15:37:16.883119+00:00 | 2023-01-10T15:37:16.883171+00:00 | 692 | false | \n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n int max_len=min(rectangles... | 4 | 0 | ['C++'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | C++ easy solution for beginner | c-easy-solution-for-beginner-by-richach1-jltk | \nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n vector<int> vec;\n int mini=INT_MAX;\n int co | Richach10 | NORMAL | 2022-05-14T22:33:19.455115+00:00 | 2022-05-14T22:46:01.792510+00:00 | 455 | false | ```\nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n vector<int> vec;\n int mini=INT_MAX;\n int count=1;\n for(int i=0;i<rectangles.size();i++){\n mini=min(rectangles[i][0],rectangles[i][1]);\n vec.push_back(mini);\n ... | 4 | 0 | ['C', 'C++'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | C++ | Simple O(N) two pass solution | c-simple-on-two-pass-solution-by-sekhar1-h33p | Find max possible square out of all rectangles\n2. Find all rectangles matching max square found in step 1\n\nclass Solution {\npublic:\n int countGoodRectan | sekhar179 | NORMAL | 2021-01-17T04:13:36.051145+00:00 | 2021-01-17T04:13:36.051178+00:00 | 296 | false | 1. Find max possible square out of all rectangles\n2. Find all rectangles matching max square found in step 1\n```\nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n int cnt = 0;\n int maxLen = 0;\n for (auto it: rectangles) {\n int len = min(it[... | 4 | 0 | ['C'] | 1 |
number-of-rectangles-that-can-form-the-largest-square | Java O(n) Solution | java-on-solution-by-mayank_pratap-2l0e | \nhttps://achievementguru.com/leetcode-1725-number-of-rectangles-that-can-form-the-largest-square-java-solution/\n\nclass Solution {\n public int countGoodRe | mayank_pratap | NORMAL | 2021-01-17T04:03:05.210357+00:00 | 2021-01-17T04:10:47.328544+00:00 | 542 | false | \nhttps://achievementguru.com/leetcode-1725-number-of-rectangles-that-can-form-the-largest-square-java-solution/\n```\nclass Solution {\n public int countGoodRectangles(int[][] rectangles) {\n int [] sq = new int[rectangles.length];\n \n for(int i=0;i<rectangles.length;i++)\n sq[i]=M... | 4 | 1 | ['Java'] | 2 |
number-of-rectangles-that-can-form-the-largest-square | Easiest C++ Solution || Beginner Friendly || Hashmap || Without using sorting || O(N) | easiest-c-solution-beginner-friendly-has-azko | Intuition\n Describe your first thoughts on how to solve this problem. \nTo maximize the side length of a square that can fit in each rectangle, use the smaller | dilpreetchhabra76 | NORMAL | 2024-12-07T23:38:12.056920+00:00 | 2024-12-07T23:38:12.056951+00:00 | 81 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo maximize the side length of a square that can fit in each rectangle, use the smaller dimension of the rectangle. Count how many rectangles can form squares with the largest possible side length.\n# Approach\n<!-- Describe your approach... | 3 | 0 | ['C++'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | [python|| O(N)] | python-on-by-sneh713-xw4p | 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 | Sneh713 | NORMAL | 2022-10-16T14:20:21.967182+00:00 | 2022-10-16T14:20:21.967230+00:00 | 453 | 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- O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- O(1)\n<!-- Add your space complexity here, ... | 3 | 0 | ['Python3'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | Beginner friendly JavaScript Solution | beginner-friendly-javascript-solution-by-9s7n | Time Complexity : O(n)\n\n/**\n * @param {number[][]} rectangles\n * @return {number}\n */\nvar countGoodRectangles = function(rectangles) {\n let count = 0, | HimanshuBhoir | NORMAL | 2022-01-26T12:12:07.731686+00:00 | 2022-01-26T12:12:07.731716+00:00 | 230 | false | **Time Complexity : O(n)**\n```\n/**\n * @param {number[][]} rectangles\n * @return {number}\n */\nvar countGoodRectangles = function(rectangles) {\n let count = 0, max = 0;\n for(let rec of rectangles){\n let len = Math.min(rec[0], rec[1]);\n if(len > max){\n count = 1;\n max ... | 3 | 0 | ['JavaScript'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | [Java] O(n) time, O(1) space | java-on-time-o1-space-by-alibekkarimov-qa34 | \nclass Solution {\n public int countGoodRectangles(int[][] rectangles) {\n int count=0, maxLen=Math.min(rectangles[0][0],rectangles[0][1]);\n | AlibekKarimov | NORMAL | 2021-10-07T14:55:09.504432+00:00 | 2021-10-07T14:55:09.504462+00:00 | 141 | false | ```\nclass Solution {\n public int countGoodRectangles(int[][] rectangles) {\n int count=0, maxLen=Math.min(rectangles[0][0],rectangles[0][1]);\n for(int i=0;i<rectangles.length;i++){\n int curLen = Math.min(rectangles[i][0],rectangles[i][1]);\n if(curLen==maxLen) count++;\n ... | 3 | 0 | [] | 0 |
number-of-rectangles-that-can-form-the-largest-square | [Java] solution without map beats 100% | java-solution-without-map-beats-100-by-v-wnyr | \nclass Solution {\n public int countGoodRectangles(int[][] rectangles) {\n int max = 0;\n int count = 0;\n for (int[] r : rectangles){\ | vinsinin | NORMAL | 2021-03-16T06:16:15.157500+00:00 | 2021-03-16T06:16:15.157545+00:00 | 223 | false | ```\nclass Solution {\n public int countGoodRectangles(int[][] rectangles) {\n int max = 0;\n int count = 0;\n for (int[] r : rectangles){\n int min = Math.min(r[0], r[1]);\n if (min > max){\n max = min;\n count = 1;\n }\n ... | 3 | 0 | ['Java'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | Java Solution beats 100% | T.C-O(n) S.C-O(1) | java-solution-beats-100-tc-on-sc-o1-by-l-kdlf | \n public int countGoodRectangles(int[][] rectangles) {\n \n\t\tint ans = -1;\n\t\tint count = 0;\n\n\t\tfor (int[] rectangle : rectangles) {\n\n\t\t\ | LegendaryCoder | NORMAL | 2021-01-21T06:20:16.397122+00:00 | 2021-01-21T06:20:16.397154+00:00 | 199 | false | \n public int countGoodRectangles(int[][] rectangles) {\n \n\t\tint ans = -1;\n\t\tint count = 0;\n\n\t\tfor (int[] rectangle : rectangles) {\n\n\t\t\tint min = Math.min(rectangle[0], rectangle[1]);\n\t\t\tif (min > ans) {\n\t\t\t\tans = min;\n\t\t\t\tcount = 1;\n\t\t\t} else if (min == ans)\n\t\t\t\tcount++;... | 3 | 0 | [] | 1 |
number-of-rectangles-that-can-form-the-largest-square | Simple JavaScript Solution | simple-javascript-solution-by-crazyspyde-64jr | \nvar countGoodRectangles = function(rectangles) {\n let count = 0\n let max = 0\n \n for(let i of rectangles){\n let side = Math.min(i[0], i | crazyspyder2020 | NORMAL | 2021-01-17T07:53:12.587593+00:00 | 2021-01-17T07:53:12.587632+00:00 | 276 | false | ```\nvar countGoodRectangles = function(rectangles) {\n let count = 0\n let max = 0\n \n for(let i of rectangles){\n let side = Math.min(i[0], i[1])\n if(side > max){\n max = side\n count = 1\n } else if(side == max) {\n count++\n }\n }\n re... | 3 | 0 | ['JavaScript'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | [C++] O(N) Time O(1) Space Solution | c-on-time-o1-space-solution-by-davidchai-5v6h | Idea:\nWe traverse the whole vector. For each rectangle\'s maxLen curLen, we compare it with the global maxLen maxLen. If\n curLen > maxLen, we know the maxLen | davidchai | NORMAL | 2021-01-17T04:13:25.315575+00:00 | 2021-01-17T04:13:46.774090+00:00 | 133 | false | Idea:\nWe traverse the whole vector. For each rectangle\'s maxLen `curLen`, we compare it with the global maxLen `maxLen`. If\n* `curLen > maxLen`, we know the `maxLen` should be updated.\n* `curLen == maxLen`, we know we should `++res`.\n* Otherwise, we just ignore.\n\n```\nclass Solution {\npublic:\n int countGood... | 3 | 1 | ['C'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | [Python3] freq table | python3-freq-table-by-ye15-serv | Algo\nFor each pair of l and w, collect the frequency table of min(l, w). Return the freq of max of such min. \n\nImplementation\n\nclass Solution:\n def cou | ye15 | NORMAL | 2021-01-17T04:03:30.523534+00:00 | 2021-01-17T04:03:30.523564+00:00 | 375 | false | **Algo**\nFor each pair of `l` and `w`, collect the frequency table of `min(l, w)`. Return the freq of max of such min. \n\n**Implementation**\n```\nclass Solution:\n def countGoodRectangles(self, rectangles: List[List[int]]) -> int:\n freq = {}\n for l, w in rectangles: \n x = min(l, w)\n ... | 3 | 0 | ['Python3'] | 2 |
number-of-rectangles-that-can-form-the-largest-square | C solution | c-solution-by-pavithrav25-523p | Code | pavithrav25 | NORMAL | 2025-01-17T14:52:03.601702+00:00 | 2025-01-17T14:52:03.601702+00:00 | 31 | false |
# Code
```c []
int countGoodRectangles(int** r, int n, int* c) {
int max = 0, cnt = 0;
for (int i = 0; i < n; i++) {
int side = r[i][0] < r[i][1] ? r[i][0] : r[i][1];
if (side > max) {
max = side;
cnt = 1;
} else if (side == max) {
cnt++;
}
... | 2 | 0 | ['C'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | Rust || beats 100% || 0ms | rust-beats-100-0ms-by-user7454af-bjce | Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n\nimpl Solution {\n pub fn count_good_rectangles(rectangles: Vec<Vec<i32>>) -> i32 | user7454af | NORMAL | 2024-06-06T20:43:50.054574+00:00 | 2024-06-06T20:43:50.054603+00:00 | 39 | false | # Complexity\n- Time complexity: $$O(n)$$\n\n- Space complexity: $$O(n)$$\n\n# Code\n```\nimpl Solution {\n pub fn count_good_rectangles(rectangles: Vec<Vec<i32>>) -> i32 {\n let mut max_side = 0;\n let mut count = 0;\n for rect in rectangles.iter() {\n let mut side = std::cmp::min(re... | 2 | 0 | ['Rust'] | 1 |
number-of-rectangles-that-can-form-the-largest-square | Easy C++ Solution | easy-c-solution-by-adityagarg217-wgod | class Solution {\npublic:\n\n int countGoodRectangles(vector>& rectangles) {\n \n\t vector ans ; \n for(int i=0 ; irectangles[i][1]){\n | adityagarg217 | NORMAL | 2023-06-05T11:38:36.558071+00:00 | 2023-06-05T11:52:29.614846+00:00 | 196 | false | class Solution {\npublic:\n\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n \n\t vector<int> ans ; \n for(int i=0 ; i<rectangles.size();i++){\n if(rectangles[i][0]>rectangles[i][1]){\n ans.push_back(rectangles[i][1]);\n }else \n ans.p... | 2 | 0 | [] | 0 |
number-of-rectangles-that-can-form-the-largest-square | Simple JAVA Solution for beginners. 2ms. Beats 92.57%. | simple-java-solution-for-beginners-2ms-b-8nhy | 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 | sohaebAhmed | NORMAL | 2023-05-09T02:23:19.039519+00:00 | 2023-05-09T02:23:19.039565+00:00 | 272 | 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 | ['Array', 'Java'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | C++ solution || O(n) || Using Map | c-solution-on-using-map-by-surya_2101-o0xy | \nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n int max_area=0;\n unordered_map<int,int>m;\n | Surya-2101 | NORMAL | 2023-03-29T17:34:26.654652+00:00 | 2023-03-29T17:34:26.654703+00:00 | 36 | false | ```\nclass Solution {\npublic:\n int countGoodRectangles(vector<vector<int>>& rectangles) {\n int max_area=0;\n unordered_map<int,int>m;\n for(int i=0;i<rectangles.size();i++)\n {\n int l=rectangles[i][0];\n int w=rectangles[i][1];\n int mini=min(l,w);\n ... | 2 | 0 | ['C'] | 0 |
number-of-rectangles-that-can-form-the-largest-square | JavaScript Time O(n) Space O(n) with HashTable | javascript-time-on-space-on-with-hashtab-rfje | Approach\nSearch through each rectangles, find the smaller side, and add one to the count number(With hash), compare to the maximum width. Return the count numb | uncle30402 | NORMAL | 2023-01-25T15:11:02.918239+00:00 | 2023-01-25T15:11:02.918287+00:00 | 296 | false | # Approach\nSearch through each rectangles, find the smaller side, and add one to the count number(With hash), compare to the maximum width. Return the count number of the largest width.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity ... | 2 | 0 | ['JavaScript'] | 2 |
number-of-rectangles-that-can-form-the-largest-square | java | java-by-niyazjava-1274 | \n public static int countGoodRectangles(int[][] rectangles) {\n int count = 0, max = 0;\n\n for (int i = 0; i < rectangles.length; i++) {\n | NiyazJava | NORMAL | 2022-10-14T08:39:43.473557+00:00 | 2022-10-14T08:39:43.473584+00:00 | 229 | false | ```\n public static int countGoodRectangles(int[][] rectangles) {\n int count = 0, max = 0;\n\n for (int i = 0; i < rectangles.length; i++) {\n int min = Math.min(rectangles[i][0], rectangles[i][1]);\n\n if (min > max) {\n max = min;\n count = 1;\n ... | 2 | 0 | ['Java'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.