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
number-of-ways-to-reorder-array-to-get-same-bst
Clear Explanation of an Easy Recursive Combinatorics Solution
clear-explanation-of-an-easy-recursive-c-683n
Intuition\n Describe your first thoughts on how to solve this problem. \nAs with most tree problems, we repeatedly explore the left and right subtrees of the tr
bigbullboy
NORMAL
2023-06-17T17:15:44.341860+00:00
2023-06-18T07:28:01.212372+00:00
130
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAs with most tree problems, we repeatedly explore the left and right subtrees of the tree to arrive at our solution. In this case, we look at how many permutations of a subtree array correspond to the same subtree.\n\n# Approach\n<!-- Des...
1
0
['Tree', 'Recursion', 'Combinatorics', 'Python3']
0
number-of-ways-to-reorder-array-to-get-same-bst
🔥🔥🔥C++ | neat and clean code | rare solution | must watch🔥🔥🔥
c-neat-and-clean-code-rare-solution-must-axxu
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
Algo-Messihas
NORMAL
2023-06-17T13:21:38.893124+00:00
2023-06-17T13:21:38.893157+00:00
33
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
['Array', 'Math', 'Divide and Conquer', 'Binary Search Tree', 'C++']
0
number-of-ways-to-reorder-array-to-get-same-bst
The Competitive Programming Solution [C++]
the-competitive-programming-solution-c-b-ml5t
This is not a typical DSA solution, and leans more towards CP. Please don\'t downvote -- I already warned you :)\n\n# Approach\n-> Fix the root and then think a
jaintle
NORMAL
2023-06-16T20:09:05.330080+00:00
2023-06-16T20:09:05.330101+00:00
89
false
This is not a typical DSA solution, and leans more towards CP. Please don\'t downvote -- I already warned you :)\n\n# Approach\n-> Fix the root and then think about combinations.\n-> Every node has two sides; left and right\n-> At the top most level, we cannot change the order ordering among the left side elements or t...
1
0
['Math', 'Divide and Conquer', 'Combinatorics', 'C++']
2
number-of-ways-to-reorder-array-to-get-same-bst
[ C++ / Java ] ✅ Easy and Clean Code 🔥 Divide and Conquer 🔥 Beats 💯✅✅
c-java-easy-and-clean-code-divide-and-co-6z7m
Please Upvote if you like my Solution \uD83E\uDD17\uD83E\uDD17\n\n# Complexity \n- Time complexity: O(N^2) \n Add your time complexity here, e.g. O(n) \n\n- Spa
sunny8080
NORMAL
2023-06-16T18:30:45.032283+00:00
2023-06-16T18:35:17.835560+00:00
348
false
# Please Upvote if you like my Solution \uD83E\uDD17\uD83E\uDD17\n\n# Complexity \n- Time complexity: $$O(N^2)$$ \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(N^2)$$ \n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n\n# C++ Code\n```\n#define ll long long\n\nclass Solution...
1
0
['Divide and Conquer', 'Dynamic Programming', 'Tree', 'C++', 'Java']
0
number-of-ways-to-reorder-array-to-get-same-bst
combination + recursion
combination-recursion-by-mr_stark-isk3
\nclass Solution {\npublic:\n vector<vector<long long int >> comb;\n int mod = 1e9+7;\n \n long long int solve(vector<int>& v)\n {\n int n
mr_stark
NORMAL
2023-06-16T16:20:28.376231+00:00
2023-06-16T16:20:28.376253+00:00
90
false
```\nclass Solution {\npublic:\n vector<vector<long long int >> comb;\n int mod = 1e9+7;\n \n long long int solve(vector<int>& v)\n {\n int n = v.size();\n if(n<=2)\n return 1;\n \n vector<int > l ,r;\n for(int i=1;i<n;i++){\n if(v[i]<v[0])\n ...
1
0
['C']
0
number-of-ways-to-reorder-array-to-get-same-bst
Go 22ms Solution
go-22ms-solution-by-mjmtg-elv3
Approach\nRecursive function (compute): This function divides the given array into two sub-arrays (namely \'smaller\' and \'larger\') based on the first element
MJMTG
NORMAL
2023-06-16T15:16:42.735321+00:00
2023-06-16T15:16:42.735358+00:00
95
false
# Approach\nRecursive function (compute): This function divides the given array into two sub-arrays (namely \'smaller\' and \'larger\') based on the first element, simulating the creation of a BST. If there is only one or no element left, it simply returns 1 (base case of recursion). It then recursively calculates the ...
1
0
['Go']
0
number-of-ways-to-reorder-array-to-get-same-bst
Easy and simple solution with explanation
easy-and-simple-solution-with-explanatio-pwk2
If you not understand problem clearly then here is explanation\nLet\'s suppose we have given array [3,4,5,1,2] and empty tree\nthen we have to place element in
Ashwini_Tiwari
NORMAL
2023-06-16T12:37:19.921343+00:00
2023-06-16T12:37:19.921378+00:00
64
false
**If you not understand problem clearly then here is explanation**\nLet\'s suppose we have given *array* [3,4,5,1,2] and empty tree\nthen we have to place element in tree by order they comes i.e.\nwe get first element 3 make it root then we have element 4 make it to right child of 3,now element 5 come make it to right ...
1
0
['C++']
0
number-of-ways-to-reorder-array-to-get-same-bst
EASY WELL EXPLAINED DP || COMBINATION SOLUTION
easy-well-explained-dp-combination-solut-5l7s
Intuition\n Describe your first thoughts on how to solve this problem. \nThe intuition behind the solution is to recursively divide the array into two parts, a
Syankita-_-
NORMAL
2023-06-16T12:31:27.224711+00:00
2023-06-16T12:31:27.224732+00:00
225
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind the solution is to recursively divide the array into two parts, a left part and a right part. The left part contains numbers smaller than the first element of the array,i.e root of the tree, and the right part contain...
1
0
['Dynamic Programming', 'Tree', 'Binary Search Tree', 'Combinatorics', 'C++']
0
number-of-ways-to-reorder-array-to-get-same-bst
Easy to understand code with nCr || C++ || Recursion || Fastest🔥
easy-to-understand-code-with-ncr-c-recur-tapn
Approach\nAs mention in the problem we have to find the number of ways to reorder the given array which generates the same tree.\nThe first element can not be r
kunal_asatkar
NORMAL
2023-06-16T12:26:05.062531+00:00
2023-06-16T12:30:05.557027+00:00
44
false
# Approach\nAs mention in the problem we have to find the number of ways to reorder the given array which generates the same tree.\nThe first element can not be rearranged because if we change its position the tree will change.\n\nThe dfs function is a recursive helper function that takes in the nums array and a 2D vec...
1
0
['C++']
0
number-of-ways-to-reorder-array-to-get-same-bst
Combinations, Modular Inverse using Fermat's Little Theorem
combinations-modular-inverse-using-ferma-uqqy
Intuition\n Describe your first thoughts on how to solve this problem. \nThe position for the root is fixed at the first position, the left and the right sub-tr
CHIYOI
NORMAL
2023-06-16T11:51:20.801062+00:00
2023-06-16T11:51:20.801082+00:00
26
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe position for the root is fixed at the first position, the left and the right sub-trees can be mixed with each other but without changing the order in each sub-tree.\n\nWe can get an initial answer, which is the number of combinations ...
1
0
['C']
1
number-of-ways-to-reorder-array-to-get-same-bst
[Python 3] Solution with real BST
python-3-solution-with-real-bst-by-deimv-ly6g
Code\n\nfrom math import comb\n\nMOD = 10**9+7\n\nclass Solution:\n def numOfWays(self, nums: List[int]) -> int:\n root = self._build_bst(nums)\n
deimvis
NORMAL
2023-06-16T10:31:59.690859+00:00
2023-06-16T10:31:59.690877+00:00
18
false
# Code\n```\nfrom math import comb\n\nMOD = 10**9+7\n\nclass Solution:\n def numOfWays(self, nums: List[int]) -> int:\n root = self._build_bst(nums)\n return self.perms(root)[1] - 1\n\n def perms(self, node):\n """ returns (size, perms) """\n if node is None:\n return 0, 1\n...
1
0
['Python3']
0
number-of-ways-to-reorder-array-to-get-same-bst
Most Complicated (But faster than 93% users) C++ Approach
most-complicated-but-faster-than-93-user-znei
Intuition\n Describe your first thoughts on how to solve this problem. \n\nI dare you to find the intuition in this programme.\n\nUsed (dp + divide and conquer
Vraj109
NORMAL
2023-06-16T08:38:37.155195+00:00
2023-06-16T08:44:09.326866+00:00
53
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nI dare you to find the intuition in this programme.\n\nUsed (dp + divide and conquer + combinatorics + Tree + dfs + math).\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nExtremely Complicated Approach consisting...
1
0
['Math', 'Divide and Conquer', 'Binary Search Tree', 'Combinatorics', 'C++']
0
number-of-ways-to-reorder-array-to-get-same-bst
Editorial Solution / Typescript / Pascal Triangle
editorial-solution-typescript-pascal-tri-e9po
\n\nfunction numOfWays(nums: number[]): number {\n const mod = BigInt(10 ** 9 + 7);\n const table: number[][] = [];\n\n // Fill Pascal Table\n for (let i =
bakunovdo
NORMAL
2023-06-16T08:09:02.411581+00:00
2023-06-16T08:09:02.411610+00:00
128
false
# \n```\nfunction numOfWays(nums: number[]): number {\n const mod = BigInt(10 ** 9 + 7);\n const table: number[][] = [];\n\n // Fill Pascal Table\n for (let i = 0; i < nums.length; i++) {\n table[i] = new Array(i + 1).fill(1);\n for (let j = 1; j < nums.length; j++) {\n if (j > i) continue;\n const ...
1
0
['TypeScript']
0
number-of-ways-to-reorder-array-to-get-same-bst
Lets make it easy. Its really easy!
lets-make-it-easy-its-really-easy-by-cod-l4o5
\n\n# Approach\nStep 1\nWe split the array into root, leftsubtree elements, rightsubtree elements.\nA simple filter loop would do that.\n\nWhy?\n We know
codshashank_1
NORMAL
2023-06-16T06:29:28.552016+00:00
2023-06-16T06:29:28.552034+00:00
230
false
\n\n# Approach\nStep 1\nWe split the array into root, leftsubtree elements, rightsubtree elements.\nA simple filter loop would do that.\n\nWhy?\n We know the fundamentals of Binary Search Tree.\n 1. All the elements in Left SubTree(lst) are smaller than Right SubTree(rst) elements.\n So the orderin...
1
0
['C++']
0
number-of-ways-to-reorder-array-to-get-same-bst
C++ | Dynamic Programming | Divide and Conquer | Combinational | Easy to Understand | <100ms
c-dynamic-programming-divide-and-conquer-hk3m
\nclass Solution {\npublic:\nconst long long mod = 1e9+7;\nvector<long long>fact;\nvoid calcFact(){\n fact[0] =1;\n fact[1] =1;\n for(long long i=2;i<1
pspraneetsehra08
NORMAL
2023-06-16T06:06:49.176949+00:00
2023-06-16T06:06:49.176975+00:00
76
false
```\nclass Solution {\npublic:\nconst long long mod = 1e9+7;\nvector<long long>fact;\nvoid calcFact(){\n fact[0] =1;\n fact[1] =1;\n for(long long i=2;i<1001;i++)\n fact[i] = (fact[i-1]*i)%mod;\n}\n\nlong long modInv(long long n,long long p){\n if(p==0)\n return 1LL;\n long long ans = modInv(n,p/2)...
1
0
['Divide and Conquer', 'Dynamic Programming', 'C', 'C++']
0
number-of-ways-to-reorder-array-to-get-same-bst
C++ Easy Understanding | | Recursion
c-easy-understanding-recursion-by-rhythm-1hj6
\nclass Solution {\n const int mod = 1e9 + 7;\n long inverse(long num) {\n if (num == 1) {\n return 1;\n }\n return mod -
rhythm_jain_
NORMAL
2023-06-16T04:32:00.760687+00:00
2023-06-16T04:32:00.760714+00:00
176
false
```\nclass Solution {\n const int mod = 1e9 + 7;\n long inverse(long num) {\n if (num == 1) {\n return 1;\n }\n return mod - mod / num * inverse(mod % num) % mod;\n }\n\n int dfs(vector<int>& nums) {\n int N = nums.size();\n if (N <= 2) return 1;\n \n ...
1
0
['Recursion', 'C']
0
number-of-ways-to-reorder-array-to-get-same-bst
DP + COMBINATRICS + RECURSION (C++)
dp-combinatrics-recursion-c-by-ankit1072-5fsw
Trick to find nCr using dp is nCr = n-1Cr-1 + n-1Cr\n\nlets suppose that we know the answer to rearrange the elements of left subtree and of the right subtre
ankit1072
NORMAL
2023-06-16T04:16:38.125765+00:00
2023-06-16T04:33:24.304737+00:00
184
false
**Trick to find nCr using dp is** nCr = n-1Cr-1 + n-1Cr\n\nlets suppose that we know the answer to rearrange the elements of left subtree and of the right subtree and now we want to construct our final answer for current root\n\nout of ```n-1``` places we need to choose ```left.size( ) ``` places and put left subtre...
1
0
['Dynamic Programming', 'Recursion', 'C', 'Combinatorics']
0
number-of-ways-to-reorder-array-to-get-same-bst
Editorial solution | C# | 100% efficient
editorial-solution-c-100-efficient-by-ba-7p78
Intuition\n Describe your first thoughts on how to solve this problem. \nFollowing the steps from the \'Editorial\' of the problem.\nhttps://leetcode.com/proble
Baymax_
NORMAL
2023-06-16T03:15:49.992718+00:00
2023-06-16T03:22:40.439375+00:00
261
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n*Following the steps from the \'Editorial\' of the problem.*\nhttps://leetcode.com/problems/number-of-ways-to-reorder-array-to-get-same-bst/editorial/\n\n***We can either implement a function to form Pascal Triangle..\n[or]\nDefine a func...
1
0
['Array', 'Math', 'Dynamic Programming', 'Binary Search Tree', 'C#']
1
number-of-ways-to-reorder-array-to-get-same-bst
Rust
rust-by-unknown-cj4r
When computing (a / b) % m in function Combination(a, b), we cannot treat it as a % m / (b % m), we can only apply % m to the final result, but overflow may hap
unknown-
NORMAL
2023-06-16T03:14:03.171445+00:00
2023-06-16T15:26:15.980250+00:00
47
false
When computing `(a / b) % m` in function `Combination(a, b)`, we cannot treat it as `a % m / (b % m)`, we can only apply `% m` to the final result, but overflow may happen when multiplying.\nWe can use `mod inserse` to transform it into `a * mod_inverse(b) % m`, then apply `% m` anywhere as we want.\n\n```\nimpl Soluti...
1
0
['Rust']
1
number-of-ways-to-reorder-array-to-get-same-bst
Ruby From Editorial, (somewhat) easy to understand
ruby-from-editorial-somewhat-easy-to-und-qh1l
\nMOD = 10 ** 9 + 7\n\ndef factorial (n)\n n.downto(1).inject(:*) || 1\nend \n\ndef comb (n, k)\n return factorial(n) / (factorial(k) * factorial(n - k))\
pharmac1st
NORMAL
2023-06-16T03:13:32.390325+00:00
2023-06-16T03:13:32.390343+00:00
34
false
```\nMOD = 10 ** 9 + 7\n\ndef factorial (n)\n n.downto(1).inject(:*) || 1\nend \n\ndef comb (n, k)\n return factorial(n) / (factorial(k) * factorial(n - k))\nend\n\ndef dfs(nums)\n return 1 if (nums.length < 3)\n left_nodes = nums.filter {|a| a < nums[0]}\n right_nodes = nums.filter {|a| a > nums[0]}\n ...
1
0
['Ruby']
0
number-of-ways-to-reorder-array-to-get-same-bst
C++ || Recursion + Combinatorics using Pascal table || Great Question
c-recursion-combinatorics-using-pascal-t-q5az
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
rajat0301tajar
NORMAL
2023-06-16T03:03:31.261140+00:00
2023-06-16T03:03:31.261159+00:00
371
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
['C++']
0
number-of-ways-to-reorder-array-to-get-same-bst
C solution
c-solution-by-jerrychiang87-jqoz
Code\n\n#define MOD 1000000007\nlong long dfs(int *nums, int numsSize, int **combination_table)\n{\n if(numsSize<3)\n return 1;\n int *large = (int*)malloc
JerryChiang87
NORMAL
2023-06-16T02:15:26.637458+00:00
2023-06-16T02:15:26.637477+00:00
172
false
# Code\n```\n#define MOD 1000000007\nlong long dfs(int *nums, int numsSize, int **combination_table)\n{\n if(numsSize<3)\n return 1;\n int *large = (int*)malloc(sizeof(int)*10000);\n int *small = (int*)malloc(sizeof(int)*10000);\n int lidx=0, sidx=0;\n for(int i=1;i<numsSize;i++)\n {\n if(nums[i]>nums[0])\n...
1
0
['C']
0
number-of-ways-to-reorder-array-to-get-same-bst
Python3 Solution
python3-solution-by-motaharozzaman1996-7xpm
\n\nclass Solution:\n def numOfWays(self, nums: List[int]) -> int:\n mod=10**9+7\n \n def f(nums):\n n=len(nums)\n
Motaharozzaman1996
NORMAL
2023-06-16T01:33:33.448132+00:00
2023-06-16T01:45:39.051352+00:00
562
false
\n```\nclass Solution:\n def numOfWays(self, nums: List[int]) -> int:\n mod=10**9+7\n \n def f(nums):\n n=len(nums)\n if n<=1:\n return len(nums) \n\n left=[i for i in nums if i<nums[0]]\n right=[i for i in nums if i>nums[0]]\n\n ...
1
0
['Python', 'Python3']
1
number-of-ways-to-reorder-array-to-get-same-bst
Easiest JAVA solution using BigInteger class of Java 🙌🙌
easiest-java-solution-using-biginteger-c-jsq5
Intuition\nFirst element is always fixed , now take rest elements and divide array in two arrays and repeat same process for each array. \n Describe your first
Vatsal_04V
NORMAL
2023-06-16T01:09:01.654820+00:00
2023-06-16T01:09:01.654837+00:00
122
false
# Intuition\nFirst element is always fixed , now take rest elements and divide array in two arrays and repeat same process for each array. \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nTake first element as root, not divide array in two parts which contains lesser elments and grea...
1
0
['Java']
1
number-of-ways-to-reorder-array-to-get-same-bst
Ruby solution with memoization and explanation (100%/100%)
ruby-solution-with-memoization-and-expla-3lew
Intuition\nUse recursion: for each tree, split it into the left subtree and the right subtree, then calculate the number of ways based on the length and structu
dtkalla
NORMAL
2023-06-16T00:59:41.276298+00:00
2023-06-18T01:39:31.832306+00:00
53
false
# Intuition\nUse recursion: for each tree, split it into the left subtree and the right subtree, then calculate the number of ways based on the length and structure of each subtree.\n\n# Approach\n0. Create a class memo to return the number of arrangements of normalized arrays. (Normalized here means it uses the numbe...
1
0
['Ruby']
0
number-of-ways-to-reorder-array-to-get-same-bst
C++ || DFS
c-dfs-by-_biranjay_kumar-5ox1
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
_Biranjay_kumar_
NORMAL
2023-06-16T00:36:27.761491+00:00
2023-06-16T00:36:27.761514+00:00
851
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
['Divide and Conquer', 'Dynamic Programming', 'Tree', 'Union Find', 'C++']
0
russian-doll-envelopes
Java NLogN Solution with Explanation
java-nlogn-solution-with-explanation-by-gq7yc
Sort the array. Ascend on width and descend on height if width are same.\n 2. Find the [longest increasing subsequence][1] based on height. \n\n\n----------\n\n
AyanamiA
NORMAL
2016-06-07T06:40:32+00:00
2018-10-23T07:13:03.686918+00:00
91,670
false
1. Sort the array. Ascend on width and descend on height if width are same.\n 2. Find the [longest increasing subsequence][1] based on height. \n\n\n----------\n\n - Since the width is increasing, we only need to consider height. \n - [3, 4] cannot contains [3, 3], so we need to put [3, 4] before [3, 3] when sorting o...
707
4
['Dynamic Programming', 'Java']
73
russian-doll-envelopes
[C++,Java, Python]Best Explanation with Pictures
cjava-pythonbest-explanation-with-pictur-73bl
If you like this solution or find it useful, please upvote this post.\n\n\tPrerequisite\n\t\n\tBefore moving on to the solution, you should know how can we find
rhythm_varshney
NORMAL
2022-05-25T03:34:26.472184+00:00
2022-05-30T07:00:18.268844+00:00
31,252
false
**If you like this solution or find it useful, please upvote this post.**\n<details>\n\t<summary>Prerequisite</summary>\n\t<br>\n\tBefore moving on to the solution, you should know how can we find the length of <strong>Longest Increasing Subsequence</strong> unsing <strong>Binary Search</strong>. You can find the detai...
410
0
['C', 'Binary Tree', 'Python', 'Java']
26
russian-doll-envelopes
JS, Python, Java, C++ | Easy LIS Solution w/ Explanation
js-python-java-c-easy-lis-solution-w-exp-wvra
(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n
sgallivan
NORMAL
2021-03-30T09:13:56.954030+00:00
2021-03-30T10:29:45.595458+00:00
13,320
false
*(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nThe naive approach here would be to try every single permutation of our envelope array (**E**), but that would be a **time complexity** of **O...
168
9
['C', 'Python', 'Java', 'JavaScript']
5
russian-doll-envelopes
C++ | O(NlogN) approach | LIS | Explaination with Comments
c-onlogn-approach-lis-explaination-with-r80np
\nclass Solution {\n static bool cmp(vector<int>& a, vector<int>& b){\n if(a[0]==b[0]) return a[1] > b[1];\n return a[0] < b[0];\n }\npublic
sahil_d70
NORMAL
2022-05-25T03:25:52.029727+00:00
2022-05-25T03:44:54.166626+00:00
19,214
false
```\nclass Solution {\n static bool cmp(vector<int>& a, vector<int>& b){\n if(a[0]==b[0]) return a[1] > b[1];\n return a[0] < b[0];\n }\npublic:\n int maxEnvelopes(vector<vector<int>>& env) {\n int n = env.size();\n \n // sorting by height & if we encounter same height\n ...
140
1
['C', 'Binary Tree']
10
russian-doll-envelopes
C++ 9-line Short and Clean O(nlogn) solution (plus classic O(n^2) dp solution).
c-9-line-short-and-clean-onlogn-solution-4thf
///O(nlogn)\n\n struct Solution {\n int maxEnvelopes(vector<pair<int, int>>& es) {\n sort(es.begin(), es.end(), [](pair<int, int> a, pair<i
fentoyal
NORMAL
2016-06-09T19:12:31+00:00
2018-09-29T15:58:15.073519+00:00
19,276
false
///O(nlogn)\n\n struct Solution {\n int maxEnvelopes(vector<pair<int, int>>& es) {\n sort(es.begin(), es.end(), [](pair<int, int> a, pair<int, int> b){\n return a.first < b.first || (a.first == b.first && a.second > b.second);});\n vector<int> dp;\n for (aut...
99
4
[]
7
russian-doll-envelopes
Simple DP solution
simple-dp-solution-by-larrywang2014-hcx2
public int maxEnvelopes(int[][] envelopes) {\n if ( envelopes == null\n || envelopes.length == 0\n || envelopes[0]
larrywang2014
NORMAL
2016-06-06T22:12:14+00:00
2018-10-20T11:27:23.290897+00:00
34,990
false
public int maxEnvelopes(int[][] envelopes) {\n if ( envelopes == null\n || envelopes.length == 0\n || envelopes[0] == null\n || envelopes[0].length == 0){\n return 0; \n }\n \n Arrays.sort(envelopes, new Comparator<int[...
83
10
[]
20
russian-doll-envelopes
[Python] 4 lines solution, explained
python-4-lines-solution-explained-by-dba-8vob
There is solution, if we use similar idea of Problems 300 (Longest Increading subsequence), because we want to find the longest increasing sub-sequence. Check
dbabichev
NORMAL
2021-03-30T11:49:35.375233+00:00
2021-03-30T11:49:35.375267+00:00
5,126
false
There is solution, if we use similar idea of Problems **300** (Longest Increading subsequence), because we want to find the longest increasing sub-sequence. Check my solution https://leetcode.com/problems/longest-increasing-subsequence/discuss/667975/Python-3-Lines-dp-with-binary-search-explained\n\nActually we can d...
67
1
[]
6
russian-doll-envelopes
Python O(nlogn) O(n) solution, beats 97%, with explanation
python-onlogn-on-solution-beats-97-with-exwsg
class Solution(object):\n def maxEnvelopes(self, envs):\n def liss(envs):\n def lmip(envs, tails, k):\n b, e
agave
NORMAL
2016-06-14T15:16:15+00:00
2018-08-23T05:36:46.414509+00:00
20,016
false
class Solution(object):\n def maxEnvelopes(self, envs):\n def liss(envs):\n def lmip(envs, tails, k):\n b, e = 0, len(tails) - 1\n while b <= e:\n m = (b + e) >> 1\n if envs[tails[m]][1] >= k[1]:\n ...
56
2
['Binary Tree', 'Python']
9
russian-doll-envelopes
Two solutions in C++, well-explained
two-solutions-in-c-well-explained-by-lhe-jth4
Solutions\n\n#### DP\nIt's quite intuitive to adopt DP to solve this problem: \n\n- sorting the envelopes first via its first value (width)\n- allocating an arr
lhearen
NORMAL
2016-08-18T02:30:44.535000+00:00
2018-10-19T06:30:52.727491+00:00
8,730
false
### Solutions\n\n#### DP\nIt's quite intuitive to adopt DP to solve this problem: \n\n- sorting the envelopes first via its first value (width)\n- allocating an array to record the maximal amount for each envelope (the maximal amount we can get ending with the current envelope)\n\nDirectly the time cost here will be o(...
55
2
[]
6
russian-doll-envelopes
The best answer your'e looking for. RECURSION|MEMOIZATION|TABULATION|1D OPTIMIZATION| BINARY SEARCH
the-best-answer-youre-looking-for-recurs-fytg
Recursion (gives TLE at test 57)\n\nclass Solution {\npublic:\n int f(int curr,int prev,vector<vector<int>>& envelopes){\n if(curr==envelopes.size()){
Akashsb
NORMAL
2023-02-22T14:09:02.443800+00:00
2023-02-22T14:09:02.443842+00:00
2,827
false
# Recursion (gives TLE at test 57)\n```\nclass Solution {\npublic:\n int f(int curr,int prev,vector<vector<int>>& envelopes){\n if(curr==envelopes.size()){\n return 0;\n }\n int notTake=0+f(curr+1,prev,envelopes);\n int take=-1e9;\n if(prev==-1 or (envelopes[prev][0]<env...
53
0
['Binary Search', 'Recursion', 'Memoization', 'C++']
4
russian-doll-envelopes
Russian Doll Envelopes | JS, Python, Java, C++ | Easy LIS Solution w/ Explanation
russian-doll-envelopes-js-python-java-c-cpzri
(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n
sgallivan
NORMAL
2021-03-30T09:14:34.934563+00:00
2021-03-30T10:29:39.002260+00:00
2,621
false
*(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nThe naive approach here would be to try every single permutation of our envelope array (**E**), but that would be a **time complexity** of **O...
37
9
[]
2
russian-doll-envelopes
Python LIS based approach
python-lis-based-approach-by-constantine-f3n4
The prerequisite for this problem is to understand and solve Longest Increasing Subsequence. So if you are familiar with LIS and have solved it, the difficulty
constantine786
NORMAL
2022-05-25T04:55:42.837316+00:00
2022-05-25T17:41:48.286978+00:00
5,498
false
The prerequisite for this problem is to understand and solve [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/). So if you are familiar with LIS and have solved it, the difficulty of this problem is reduced.\n\nNow, before we can start implementing LIS for this problem, we n...
32
0
['Python', 'Python3']
3
russian-doll-envelopes
C++ Time O(NlogN) Space O(N) , similar to LIS nlogn solution
c-time-onlogn-space-on-similar-to-lis-nl-43y2
bool cmp (pair<int, int> i, pair<int, int> j) {\n if (i.first == j.first)\n return i.second > j.second;\n return i.first < j.first;\n
jordandong
NORMAL
2016-06-07T06:12:40+00:00
2016-06-07T06:12:40+00:00
4,855
false
bool cmp (pair<int, int> i, pair<int, int> j) {\n if (i.first == j.first)\n return i.second > j.second;\n return i.first < j.first;\n }\n \n class Solution {\n public:\n int maxEnvelopes(vector<pair<int, int>>& envelopes) {\n int N = envelopes.size();\n ...
30
1
[]
2
russian-doll-envelopes
O(Nlog(N)) python solution explained
onlogn-python-solution-explained-by-erjo-evcs
Sort the envelopes first by increasing width. For each block of same-width envelopes, sort by decreasing height.\n\nThen find the longest increasing subsequence
erjoalgo
NORMAL
2017-11-24T01:53:08.144000+00:00
2018-10-11T00:03:26.019057+00:00
3,029
false
Sort the envelopes first by increasing width. For each block of same-width envelopes, sort by decreasing height.\n\nThen find the longest increasing subsequence of heights.\n\nSince each same-width subarray is non-increasing in height, we can never pick more than one height within each width (otherwise heights would b...
28
3
[]
5
russian-doll-envelopes
Short and simple Java solution (15 lines)
short-and-simple-java-solution-15-lines-lallh
\n public int maxEnvelopes(int[][] envelopes) {\n Arrays.sort(envelopes, (a, b) -> a[0] - b[0]);\n int max = 0;\n int dp [] = new int [e
chern_yee
NORMAL
2016-06-08T17:44:04+00:00
2018-09-07T08:40:28.724542+00:00
6,493
false
\n public int maxEnvelopes(int[][] envelopes) {\n Arrays.sort(envelopes, (a, b) -> a[0] - b[0]);\n int max = 0;\n int dp [] = new int [envelopes.length];\n for(int i = 0; i < envelopes.length; i++){\n dp[i] = 1;\n for(int j = 0; j < i; j++){\n if(enve...
24
2
['Java']
4
russian-doll-envelopes
95% faster | C++ | N log N using Binary Search | LIS(concept)
95-faster-c-n-log-n-using-binary-search-7vbzv
\nclass Solution {\npublic:\n static bool compare(vector<int>&a , vector<int>& b)\n {\n return a[0]==b[0]?a[1]>b[1]:a[0]<b[0];\n }\n int maxEnv
crag
NORMAL
2021-03-31T11:35:14.361999+00:00
2021-03-31T11:35:14.362037+00:00
2,495
false
```\nclass Solution {\npublic:\n static bool compare(vector<int>&a , vector<int>& b)\n {\n return a[0]==b[0]?a[1]>b[1]:a[0]<b[0];\n }\n int maxEnvelopes(vector<vector<int>>&a) {\n sort(a.begin(),a.end(),compare);\n vector<int>dp;\n for(auto i:a)\n {\n auto it=lower_bound(dp.b...
19
0
['Dynamic Programming', 'C', 'Binary Tree']
3
russian-doll-envelopes
[C++] - Classic DP problem variant
c-classic-dp-problem-variant-by-morning_-3b3a
Variant of Classic DP - LIS problem :\nTime Complexity - O(n^2)\nSpace Complexity - O(n)\n\n\nclass Solution {\npublic:\n int maxEnvelopes(vector<vector<int>
morning_coder
NORMAL
2021-03-30T07:44:14.656352+00:00
2021-03-31T06:28:06.307908+00:00
3,654
false
**Variant of Classic DP - LIS problem :**\nTime Complexity - O(n^2)\nSpace Complexity - O(n)\n\n```\nclass Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n sort(begin(envelopes),end(envelopes),[]\n (const vector<int> &a,const vector<int> &b){\n return (a[0...
15
3
['Dynamic Programming', 'C', 'C++']
4
russian-doll-envelopes
Binary Search (T.C=O(nlogn),S.C=O(n)) Approach || Beats 98%
binary-search-tconlognscon-approach-beat-rfjq
\n\n# Approach: \n Describe your approach to solving the problem. \n1. Sorting:\n\n- First, sort the envelopes by their width in ascending order. If two envelop
prayashbhuria931
NORMAL
2024-08-08T20:52:42.892013+00:00
2024-08-08T20:52:42.892030+00:00
1,448
false
\n\n# Approach: \n<!-- Describe your approach to solving the problem. -->\n1. Sorting:\n\n- First, sort the envelopes by their width in ascending order. If two envelopes have the same width, sort them by height in descending order. This ensures that when processing envelopes with the same width, you only consider the h...
14
0
['Binary Search', 'Sorting', 'C++']
0
russian-doll-envelopes
[Java] LIS Revisited | Binary Search Best Explanation
java-lis-revisited-binary-search-best-ex-ygzg
Please upvote if you like the soltion\n\n\tPrerequisite\n\t\n\tBefore moving on to the solution, you should know how can we find the length of Longest Increasin
rhythm_varshney
NORMAL
2022-01-31T15:30:31.333261+00:00
2022-05-25T03:31:01.474718+00:00
1,183
false
**Please upvote if you like the soltion**\n<details>\n\t<summary>Prerequisite</summary>\n\t<br>\n\tBefore moving on to the solution, you should know how can we find the length of <strong>Longest Increasing Subsequence</strong> unsing <strong>Binary Search</strong>. You can find the detailed explanation of the logic on ...
14
0
['Binary Tree']
2
russian-doll-envelopes
10 lines Python code beats %96.
10-lines-python-code-beats-96-by-geeti-rpyv
\nclass Solution(object):\n def maxEnvelopes(self, envelopes):\n des_ht = [a[1] for a in sorted(envelopes, key = lambda x: (x[0], -x[1]))]\n dp
geeti
NORMAL
2016-07-29T00:18:43.484000+00:00
2016-07-29T00:18:43.484000+00:00
3,384
false
```\nclass Solution(object):\n def maxEnvelopes(self, envelopes):\n des_ht = [a[1] for a in sorted(envelopes, key = lambda x: (x[0], -x[1]))]\n dp, l = [0] * len(des_ht), 0\n for x in des_ht:\n i = bisect.bisect_left(dp, x, 0, l)\n dp[i] = x\n if i == l:\n ...
14
0
[]
4
russian-doll-envelopes
✅C++ || Recursion->Memoization->BinarySearch
c-recursion-memoization-binarysearch-by-n8pdx
Method -1 [Recursion] Gives TLE!\n\n\n\tclass Solution {\n\tpublic:\n\t// LIS\n\t\tint f(int i,int prev,vector>& env,int n){\n\t\t\tif(i==n) return 0;\n\t\t
abhinav_0107
NORMAL
2022-09-06T06:53:27.590424+00:00
2022-09-06T06:54:35.519748+00:00
2,070
false
# Method -1 [Recursion] Gives TLE!\n![image](https://assets.leetcode.com/users/images/1530a62f-ec33-4ff3-8bbb-4b3299483ad7_1662447073.3290262.png)\n\n\tclass Solution {\n\tpublic:\n\t// LIS\n\t\tint f(int i,int prev,vector<vector<int>>& env,int n){\n\t\t\tif(i==n) return 0;\n\t\t\tint pick=INT_MIN;\n\t\t\tif(prev==...
13
0
['Binary Search', 'Recursion', 'Memoization', 'C', 'Sorting', 'C++']
0
russian-doll-envelopes
Backtracking solution that you will be expected to provide in interviews [ACCEPTED]
backtracking-solution-that-you-will-be-e-zgc4
The O(nlogn) solution is unreasonable for an interviewer to expect. The solution below should be more than sufficient for you to pass the interview:\n\n\nclass
topologicallysorted
NORMAL
2020-01-30T17:52:59.531466+00:00
2020-02-01T07:47:30.930062+00:00
826
false
The O(nlogn) solution is unreasonable for an interviewer to expect. The solution below should be more than sufficient for you to pass the interview:\n\n```\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n // Sort in increasing order by\n // any dimension.\n // This is an optimi...
12
1
[]
7
russian-doll-envelopes
C++ | DP | LIS
c-dp-lis-by-iashi_g-ejtf
\nclass Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n if (envelopes.empty()) return 0;\n sort(envelopes.begin(), e
iashi_g
NORMAL
2021-09-23T04:41:50.123565+00:00
2021-09-23T04:41:50.123607+00:00
1,007
false
```\nclass Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n if (envelopes.empty()) return 0;\n sort(envelopes.begin(), envelopes.end());\n vector<int> dp(envelopes.size(), 1);\n for (int i = 0; i < envelopes.size(); ++i)\n for (int j = 0; j < i; ++j)\n...
11
1
['Dynamic Programming', 'C']
3
russian-doll-envelopes
JAVA || LIS Application
java-lis-application-by-himanshuchhikara-5q51
Explanation:\nBasically its an 2-D version of longest-increasing-subsequence and there is a 3-D version also which is very popular interview problem of Codenati
himanshuchhikara
NORMAL
2021-03-30T13:28:09.424719+00:00
2021-03-30T13:28:09.424749+00:00
1,348
false
**Explanation:**\nBasically its an 2-D version of [longest-increasing-subsequence](https://leetcode.com/problems/longest-increasing-subsequence/) and there is a 3-D version also which is very popular interview problem of Codenation and Google [Box-stacking] .\n\nNote: `One envelope can fit into another if and only if b...
11
2
['Dynamic Programming', 'Binary Tree', 'Java']
3
russian-doll-envelopes
Clean and short nlogn solution
clean-and-short-nlogn-solution-by-jwzh-jd7x
See more explanation in [Longest Increasing Subsequence Size (N log N)][1]\n\n def maxEnvelopes(self, envelopes):\n def bin_search(A, key):\n
jwzh
NORMAL
2016-06-07T04:18:30+00:00
2016-06-07T04:18:30+00:00
4,468
false
See more explanation in [Longest Increasing Subsequence Size (N log N)][1]\n\n def maxEnvelopes(self, envelopes):\n def bin_search(A, key):\n l, r = 0, len(A)\n while l < r:\n mid = (l+r)/2\n if A[mid][1] < key[1]:\n l = mid + 1\n ...
11
2
['Python']
4
russian-doll-envelopes
Russian Doll Envelopes || simple c++ solution || dynamic programming
russian-doll-envelopes-simple-c-solution-ne56
Simple C++ solution \nUsing dynamic programming\n\n\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n \n sort(envelopes.begin(), envelopes.end(),
rawat_abhi33
NORMAL
2022-05-25T03:59:37.075083+00:00
2022-05-25T03:59:37.075122+00:00
3,663
false
Simple C++ solution \nUsing dynamic programming\n\n``` \n int maxEnvelopes(vector<vector<int>>& envelopes) {\n \n sort(envelopes.begin(), envelopes.end(), [](vector<int>& a, vector<int>& b) \n -> bool {return a[0] == b[0] ? b[1] < a[1] : a[0] < b[0];});\n vector<int> dp;\n for (auto&...
10
0
['Dynamic Programming', 'C']
0
russian-doll-envelopes
JAVA SOLUTION | 10 Lines
java-solution-10-lines-by-ghrushneshr25-iwfc
\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n Arrays.sort(envelopes, (a,b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);\n
ghrushneshr25
NORMAL
2022-05-25T02:44:12.799221+00:00
2022-05-25T02:44:12.799252+00:00
3,095
false
```\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n Arrays.sort(envelopes, (a,b) -> a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);\n int[] dp = new int[envelopes.length];\n int ans = 0;\n for (int[] env : envelopes) {\n int height = env[1];\n int left ...
10
0
['Dynamic Programming', 'Binary Tree', 'Java']
1
russian-doll-envelopes
Python [Reduce to 1D]
python-reduce-to-1d-by-gsan-wknc
Reduce the problem to 1D and then it becomes Leetcode Problem 300 - Longest Increasing Subsequence.\nOnce the letters are sorted in increasing width, we only ne
gsan
NORMAL
2021-03-30T11:10:00.934440+00:00
2021-03-31T00:07:17.575332+00:00
484
false
Reduce the problem to 1D and then it becomes Leetcode Problem 300 - Longest Increasing Subsequence.\nOnce the letters are sorted in increasing width, we only need to sort based on height. Same width envelopes can be traversed in decreasing height because they will never be included in the same sequence.\n\nIf all the l...
10
2
[]
1
russian-doll-envelopes
C++ N log N solution
c-n-log-n-solution-by-wuyang-a0b4
\nclass Solution {\npublic:\n // Dynamic Programming with Binary Search\n // Time complexity : O(nlogn). Sorting and binary search both take nlogn time.\n
wuyang
NORMAL
2021-02-01T15:32:49.361269+00:00
2021-02-01T15:32:49.361311+00:00
1,240
false
```\nclass Solution {\npublic:\n // Dynamic Programming with Binary Search\n // Time complexity : O(nlogn). Sorting and binary search both take nlogn time.\n // Space complexity : O(n). dp array of size n is used.\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n // For each envelope, sorted by en...
10
1
['Dynamic Programming', 'C', 'Binary Tree']
1
russian-doll-envelopes
C++ DP version, Time O(N^2) Space O(N)
c-dp-version-time-on2-space-on-by-jordan-exvg
bool cmp (pair<int, int> i, pair<int, int> j) {\n if (i.first == j.first)\n return i.second < j.second;\n return i.first
jordandong
NORMAL
2016-06-06T22:18:46+00:00
2016-06-06T22:18:46+00:00
2,554
false
bool cmp (pair<int, int> i, pair<int, int> j) {\n if (i.first == j.first)\n return i.second < j.second;\n return i.first < j.first;\n }\n \n class Solution {\n public:\n int maxEnvelopes(vector<pair<int, int>>& envelopes) {\n ...
10
1
[]
3
russian-doll-envelopes
No DP| Using Binary Search & LIS| CPP| Java| C| Python| Intuition| Approach
no-dp-using-binary-search-lis-cpp-java-c-7epf
Intuition\nThe problem of Russian doll envelopes is a variation of the longest increasing subsequence problem (LIS). The goal is to find the largest set of enve
vaib8557
NORMAL
2024-06-25T11:15:18.917090+00:00
2024-06-25T11:15:18.917109+00:00
1,439
false
# Intuition\nThe problem of Russian doll envelopes is a variation of the longest increasing subsequence problem (LIS). The goal is to find the largest set of envelopes such that each envelope can fit into the next one in the set. To do this, we need to sort the envelopes and then find the LIS based on their dimensions....
9
0
['Binary Search', 'Dynamic Programming', 'C', 'Python', 'C++', 'Java']
1
russian-doll-envelopes
354: Space 98.16%, Solution with step by step explanation
354-space-9816-solution-with-step-by-ste-zo7g
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. We first sort the envelopes based on width in ascending order, and if
Marlen09
NORMAL
2023-03-02T06:14:26.844165+00:00
2023-03-02T06:14:26.844196+00:00
2,559
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. We first sort the envelopes based on width in ascending order, and if the widths are equal, we sort them based on height in descending order. This is because when we are trying to find the maximum number of envelopes we c...
9
0
['Array', 'Binary Search', 'Dynamic Programming', 'Python', 'Python3']
2
russian-doll-envelopes
java easy to understand | dynamic programming | longest increasing sub sequence
java-easy-to-understand-dynamic-programm-pps8
\n\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n \n int omax = 0;\n Arrays.sort(envelopes,(a,b)->(a[0]-b[0]));\n
rmanish0308
NORMAL
2021-10-28T14:55:28.800721+00:00
2021-10-28T14:55:28.800772+00:00
700
false
```\n\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n \n int omax = 0;\n Arrays.sort(envelopes,(a,b)->(a[0]-b[0]));\n int[] dp = new int[envelopes.length];\n for(int i=0;i<envelopes.length;i++)\n {\n dp[i] = 1; \n for(int j=0;j<i;j++)...
9
2
['Dynamic Programming', 'Java']
1
russian-doll-envelopes
Gives TLE | Longest Increasing Subsequence variant | With explaination
gives-tle-longest-increasing-subsequence-7wtu
I know this solution gives TLE but for me it seems more intuitive. It may not pass all the cases of this question but you can definitely share it with the inter
iashi_g
NORMAL
2023-06-06T04:45:05.917980+00:00
2024-01-05T09:28:10.934216+00:00
2,473
false
# I know this solution gives TLE but for me it seems more intuitive. It may not pass all the cases of this question but you can definitely share it with the interviewer in actual interview.\n\n**Note - Despite two test cases exceeding the time limit, I am sharing the following code as it is more intuitive. You can give...
8
0
['C++']
2
russian-doll-envelopes
C++ | Simple binary search solution
c-simple-binary-search-solution-by-nimes-w76q
Note : Sort hight in decreasing order when width is same.\n\nclass Solution {\npublic:\n int bSearch(vector<int>& vec, int maxVal, vector<vector<int>>& envel
Nimesh-Srivastava
NORMAL
2022-05-25T01:08:11.473854+00:00
2022-05-25T01:08:11.473884+00:00
4,075
false
**Note :** Sort `hight` in decreasing order when `width` is same.\n```\nclass Solution {\npublic:\n int bSearch(vector<int>& vec, int maxVal, vector<vector<int>>& envelopes, int i){\n int l = 0;\n int r = maxVal;\n \n int temp = maxVal;\n \n while(l <= r){\n int m...
8
2
['Dynamic Programming', 'C', 'Binary Tree', 'C++']
6
russian-doll-envelopes
Golang N log N solution
golang-n-log-n-solution-by-wuyang-9qmo
\n// Dynamic Programming with Binary Search\n// Time complexity : O(nlogn). Sorting and binary search both take nlogn time.\n// Space complexity : O(n). dp arra
wuyang
NORMAL
2021-02-01T15:58:53.084034+00:00
2021-02-01T15:58:53.084068+00:00
410
false
```\n// Dynamic Programming with Binary Search\n// Time complexity : O(nlogn). Sorting and binary search both take nlogn time.\n// Space complexity : O(n). dp array of size n is used.\nfunc maxEnvelopes(envelopes [][]int) int {\n\t// For each envelope, sorted by envelope[0] first, so envelope[1] is the the longest\n\t/...
8
1
['Dynamic Programming', 'Binary Tree', 'Go']
1
russian-doll-envelopes
Python 5 lines short code
python-5-lines-short-code-by-rudy-mpbx
python\nclass Solution:\n def maxEnvelopes(self, es):\n es.sort(key=lambda x: (x[0], -x[1]))\n heights = [0x3f3f3f3f] * len(es)\n for _,
rudy__
NORMAL
2019-12-31T12:48:53.461537+00:00
2019-12-31T13:19:50.957023+00:00
784
false
```python\nclass Solution:\n def maxEnvelopes(self, es):\n es.sort(key=lambda x: (x[0], -x[1]))\n heights = [0x3f3f3f3f] * len(es)\n for _, h in es:\n heights[bisect.bisect_left(heights, h)] = h\n return bisect.bisect_right(heights, 0x3f3f3f3f - 1)\n\n```
8
1
[]
1
russian-doll-envelopes
Python solution based on LIS
python-solution-based-on-lis-by-giiia-arp7
It's a problem based on LIS. \nDP solution for LIS is N^2 which will TLE here.\nUsing Binary Search approach will get accepted.\n\nhttps://leetcode.com/problem
giiia
NORMAL
2016-07-15T18:54:40.784000+00:00
2016-07-15T18:54:40.784000+00:00
2,308
false
It's a problem based on LIS. \nDP solution for LIS is N^2 which will TLE here.\nUsing Binary Search approach will get accepted.\n\nhttps://leetcode.com/problems/longest-increasing-subsequence/\n\n def maxEnvelopes(self, envelopes):\n """\n :type envelopes: List[List[int]]\n :rtype: int\n ...
8
1
['Python']
3
russian-doll-envelopes
C++ solutions || easy to solve
c-solutions-easy-to-solve-by-infox_92-p3bp
\nclass Solution {\npublic:\n static bool compare(vector<int>&a , vector<int>& b)\n {\n return a[0]==b[0]?a[1]>b[1]:a[0]<b[0];\n }\n int maxEnv
Infox_92
NORMAL
2022-11-02T09:28:47.328991+00:00
2022-11-02T09:28:47.329032+00:00
1,888
false
```\nclass Solution {\npublic:\n static bool compare(vector<int>&a , vector<int>& b)\n {\n return a[0]==b[0]?a[1]>b[1]:a[0]<b[0];\n }\n int maxEnvelopes(vector<vector<int>>&a) {\n sort(a.begin(),a.end(),compare);\n vector<int>dp;\n for(auto i:a)\n {\n auto it=lower_bound(dp.b...
7
0
['C', 'C++']
0
russian-doll-envelopes
LIS | run time : O(n logn) | space : O(n)
lis-run-time-on-logn-space-on-by-lowkeyi-7jby
\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n Arrays.sort(envelopes, (a, b) -> a[0] != b[0] ? a[0] - b[0] : b[1] - a[1]);\n
lowkeyish
NORMAL
2022-05-26T16:23:46.875796+00:00
2022-05-26T16:23:46.875823+00:00
848
false
```\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n Arrays.sort(envelopes, (a, b) -> a[0] != b[0] ? a[0] - b[0] : b[1] - a[1]);\n List<Integer> result = new ArrayList<>();\n result.add(envelopes[0][1]);\n for (int i = 1; i < envelopes.length; ++i) {\n if (res...
7
0
['Dynamic Programming', 'Binary Tree', 'Java']
0
russian-doll-envelopes
python O(NlogN) solution, DP, binary search is not used
python-onlogn-solution-dp-binary-search-v5rv0
\nclass Solution:\n def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n # sort the width by ascending order, the height by descending order\n
shun6096tw
NORMAL
2022-05-13T08:00:28.063887+00:00
2022-05-13T08:00:28.063911+00:00
908
false
```\nclass Solution:\n def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n # sort the width by ascending order, the height by descending order\n envelopes.sort(key=lambda x: (x[0], -x[1]))\n tops = []\n for e in envelopes:\n if tops and tops[-1][0] < e[0] and tops[-1][...
7
0
['Dynamic Programming', 'Python']
1
russian-doll-envelopes
Java Simple and easy solution, 8 ms, faster than 98.48%, T O nlogn, clean code with comments
java-simple-and-easy-solution-8-ms-faste-v7uw
PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n //sort the enevelope\n //as incr
satyaDcoder
NORMAL
2021-03-31T09:09:51.701825+00:00
2021-03-31T09:09:51.701855+00:00
468
false
**PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n```\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n //sort the enevelope\n //as increasing of width, when both width is same, then sort by decreasing order heights\n Arrays.sort(envelopes, (a, b) -> (a[0] == b[0]) ? (b[1] - a[1]...
7
0
['Java']
1
russian-doll-envelopes
Python O(nlogn) - a tricky sorting to solve the 2-D dilemma
python-onlogn-a-tricky-sorting-to-solve-w4yny
On the first look of this problem, we should be able to come up with sorting the envelopes from small to large. Something like sort(envelopes). Firstly sort by
hammer001
NORMAL
2019-05-08T23:15:58.134180+00:00
2019-05-08T23:15:58.134246+00:00
692
false
On the first look of this problem, we should be able to come up with sorting the envelopes from small to large. Something like `sort(envelopes)`. Firstly **sort by the first dimension (let\'s say width), then use the second dimension data (height) to solve the LIS problem**. However, without carefully modifying your so...
7
0
[]
2
russian-doll-envelopes
Python 6 lines bisect solution
python-6-lines-bisect-solution-by-cenkay-853y
I don\'t go much into details. \n The method is all over the discussion, "longest increasing subsequence" tail method.\n We simply catch the minimum height for
cenkay
NORMAL
2018-10-19T10:51:26.456095+00:00
2018-10-22T20:17:32.966354+00:00
579
false
* I don\'t go much into details. \n* The method is all over the discussion, "longest increasing subsequence" tail method.\n* We simply catch the minimum height for specified number of dolls or length of tails in other words.\n* We reversed heights of same widths in envelopes array because it would continue adding anoth...
7
1
[]
1
russian-doll-envelopes
LIS - 💯🚀 single pattern to solve all LIS problems
lis-single-pattern-to-solve-all-lis-prob-kcw5
300. Longest Increasing Subsequence\n213. House Robber II\n198. House Robber\n740. Delete and Earn\n\n\n\n# Code\njava []\nimport java.util.Arrays;\n\npublic cl
Dixon_N
NORMAL
2024-09-15T18:04:15.219169+00:00
2024-09-15T18:04:15.219208+00:00
1,570
false
[300. Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/solutions/5574584/longest-increasing-subsequence-one-stop-template/)\n[213. House Robber II](https://leetcode.com/problems/house-robber-ii/solutions/5791343/house-robber-i-ii-beats-100/)\n[198. House Robber](https://leetc...
6
0
['Dynamic Programming', 'Java']
7
russian-doll-envelopes
Sort + LIS | C++
sort-lis-c-by-tusharbhart-kwaf
\nclass Solution {\n static bool cmp(vector<int> &a, vector<int> &b) {\n return a[0] == b[0] ? a[1] > b[1] : a[0] < b[0];\n }\npublic:\n int max
TusharBhart
NORMAL
2023-04-29T14:18:32.731244+00:00
2023-04-29T14:18:32.731281+00:00
1,734
false
```\nclass Solution {\n static bool cmp(vector<int> &a, vector<int> &b) {\n return a[0] == b[0] ? a[1] > b[1] : a[0] < b[0];\n }\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n sort(envelopes.begin(), envelopes.end(), cmp);\n\n vector<int> v;\n for(auto e : envelopes...
6
0
['Binary Search', 'Sorting', 'C++']
0
russian-doll-envelopes
C# || NLogN || Binary search || DP
c-nlogn-binary-search-dp-by-cdev-p7xg
\n public int MaxEnvelopes(int[][] envelopes)\n {\n Array.Sort(envelopes, (a, b) => a[0] == b[0] ? b[1].CompareTo(a[1]) : a[0].CompareTo(b[0]));\n\
CDev
NORMAL
2022-05-25T01:39:59.552786+00:00
2022-05-25T01:39:59.552820+00:00
430
false
```\n public int MaxEnvelopes(int[][] envelopes)\n {\n Array.Sort(envelopes, (a, b) => a[0] == b[0] ? b[1].CompareTo(a[1]) : a[0].CompareTo(b[0]));\n\n int[] dp = new int[envelopes.Length];\n int len = 0;\n foreach(int[] envelope in envelopes){\n int index = Array.BinarySear...
6
0
['Binary Search', 'Dynamic Programming']
1
russian-doll-envelopes
Russian Doll Envelopes | Easy DP solution | simple trick explained !!!
russian-doll-envelopes-easy-dp-solution-s0n0z
The trick is, we first sort the envolopes based on their width, Then the problem now turned into finding longest Increasing subsequence(LIS), so we just need to
srinivasteja18
NORMAL
2021-03-30T07:53:30.093498+00:00
2021-03-30T08:45:41.933645+00:00
416
false
The trick is, we first sort the envolopes based on their width, Then the problem now turned into finding **longest Increasing subsequence(LIS**), so we just need to find **LIS on heights of envolopes** but including some edges cases. \nLets see the edge cases to understand it more..\nconsider, `envolope = [[2,3],[5,8],...
6
1
[]
0
russian-doll-envelopes
Python N Log N solution
python-n-log-n-solution-by-wuyang-i99t
\nclass Solution:\n # Dynamic Programming with Binary Search\n # Time complexity : O(nlogn). Sorting and binary search both take nlogn time.\n # Space
wuyang
NORMAL
2021-02-01T15:51:42.197222+00:00
2021-02-01T15:51:42.197248+00:00
566
false
```\nclass Solution:\n # Dynamic Programming with Binary Search\n # Time complexity : O(nlogn). Sorting and binary search both take nlogn time.\n # Space complexity : O(n). dp array of size n is used.\n def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n # For each envelope, sorted by envelo...
6
0
['Dynamic Programming', 'Binary Tree', 'Python']
1
russian-doll-envelopes
[Python] Simple DP NlogN solution
python-simple-dp-nlogn-solution-by-101le-r1x5
\nclass Solution:\n def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n ## RC ##\n ## APPROACH : DP ##\n ## Similar to Leetcode
101leetcode
NORMAL
2020-06-21T22:42:58.191758+00:00
2020-06-21T22:42:58.191794+00:00
1,096
false
```\nclass Solution:\n def maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n ## RC ##\n ## APPROACH : DP ##\n ## Similar to Leetcode : 300 Longest Increasing Subsequence ##\n \n\t\t## TIME COMPLEXITY : O(NlogN) ##\n\t\t## SPACE COMPLEXITY : O(N) ##\n\n ## LIS : replace large...
6
0
['Python', 'Python3']
0
russian-doll-envelopes
easy peasy python O(nlogn) solution with comments
easy-peasy-python-onlogn-solution-with-c-1s7w
\tdef maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n # sort in one property and find the longest increasing subsequence\n # in the other
lostworld21
NORMAL
2019-09-19T16:50:18.287688+00:00
2019-09-19T16:50:18.287738+00:00
1,536
false
\tdef maxEnvelopes(self, envelopes: List[List[int]]) -> int:\n # sort in one property and find the longest increasing subsequence\n # in the other property, that\'s it\n # to avoid cases such as [(3, 4), (3, 6)] - output should be 1\n # sort the (w) in ascending and (h) in descending\n \n...
6
0
['Binary Tree', 'Python', 'Python3']
0
russian-doll-envelopes
beat 99.78% user with cpp|| LIS reference || well commented code
beat-9978-user-with-cpp-lis-reference-we-3hux
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
gyuyul
NORMAL
2024-09-02T11:24:35.120032+00:00
2024-09-15T14:32:29.190672+00:00
455
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
['C++']
0
russian-doll-envelopes
using dynamic programming (binary search on LIS)
using-dynamic-programming-binary-search-l9npb
Intuition\nTo find the maximum number of envelopes that can be nested (Russian-dolled), we need to treat it like finding the Longest Increasing Subsequence (LIS
saivishal87
NORMAL
2024-06-13T12:02:27.306561+00:00
2024-06-13T12:02:27.306583+00:00
784
false
# Intuition\nTo find the maximum number of envelopes that can be nested (Russian-dolled), we need to treat it like finding the Longest Increasing Subsequence (LIS), but in two dimensions (width and height). By sorting and then applying a modified LIS algorithm, we can efficiently solve the problem.\n\n# Approach\nSorti...
5
0
['Binary Search', 'Dynamic Programming', 'C++']
0
russian-doll-envelopes
[C++] Binary Search
c-binary-search-by-harsh__18-r4sg
\tclass Solution {\n\t\tprivate:\n\n\t\t\tint solve(int n,vector &nums){\n\n\t\t\t\tvector ans;\n\t\t\t\tans.push_back(nums[0]);\n\n\t\t\t\tfor(int i = 1; i < n
Harsh__18
NORMAL
2022-08-13T04:45:09.545165+00:00
2022-08-13T04:45:09.545211+00:00
906
false
\tclass Solution {\n\t\tprivate:\n\n\t\t\tint solve(int n,vector<int> &nums){\n\n\t\t\t\tvector<int> ans;\n\t\t\t\tans.push_back(nums[0]);\n\n\t\t\t\tfor(int i = 1; i < n; i++){\n\t\t\t\t\tif(nums[i] > ans.back()){\n\t\t\t\t\t\tans.push_back(nums[i]);\n\t\t\t\t\t}else{\n\t\t\t\t\t\tint index = lower_bound(ans.begin(),a...
5
0
['Dynamic Programming', 'C', 'Sorting', 'C++']
1
russian-doll-envelopes
LIS | O(NlogN) | Easy to understand | Intuitive
lis-onlogn-easy-to-understand-intuitive-r0p4k
Longest Increasing Subsequence in 2 dimension!\nFirstly, if you have solved the Longest Increasing Subsequence (LIS) question, you\'ve perhaps related this ques
deepjyotide13
NORMAL
2022-07-10T21:58:53.621024+00:00
2022-07-26T19:26:39.395882+00:00
944
false
# Longest Increasing Subsequence in 2 dimension!\nFirstly, if you have solved the `Longest Increasing Subsequence (LIS)` question, you\'ve perhaps related this question to LIS in some way or the other, if so, you\'re in the right track. In LIS we found the longest increasing subsequence in an 1D array but in this quest...
5
0
['Dynamic Programming', 'C', 'Binary Tree']
1
russian-doll-envelopes
C++ || Sorting and LIS ||
c-sorting-and-lis-by-pandeyji2023-20fz
\nclass Solution {\npublic:\n \n int find_bound(vector<int> &dp,int target){\n \n int pos = dp.size();\n \n int low = 0;\n int
pandeyji2023
NORMAL
2022-05-25T17:20:27.033220+00:00
2022-05-25T17:25:34.171309+00:00
538
false
```\nclass Solution {\npublic:\n \n int find_bound(vector<int> &dp,int target){\n \n int pos = dp.size();\n \n int low = 0;\n int high = dp.size()-1;\n \n while(low<=high){\n \n int mid = low + (high-low)/2;\n \n if(dp[mid]>=target){\...
5
0
[]
0
russian-doll-envelopes
C++ || LIS || Binary Search || with detailed comments
c-lis-binary-search-with-detailed-commen-weqx
c++\nclass Solution {\npublic:\n static bool my_comp(vector<int> &a, vector<int> &b){\n if (a[0] == b[0]) {\n return (a[1] > b[1]);\n
dha72
NORMAL
2022-05-25T16:54:19.402997+00:00
2022-05-25T16:54:19.403034+00:00
434
false
```c++\nclass Solution {\npublic:\n static bool my_comp(vector<int> &a, vector<int> &b){\n if (a[0] == b[0]) {\n return (a[1] > b[1]);\n }\n return a[0] < b[0];\n }\n \n int maxEnvelopes(vector<vector<int>>& envelopes) {\n /* Sort envelopes in increasing order of width...
5
0
['C']
0
russian-doll-envelopes
4 line of code in c++ using dp
4-line-of-code-in-c-using-dp-by-kkg2002-ghr1
```\n// please upvote if you like it\nclass Solution {\npublic:\n int maxEnvelopes(vector>& E) {\n sort(E.begin(), E.end(), \n -> bool {r
kkg2002
NORMAL
2022-05-25T00:38:55.298863+00:00
2022-05-25T00:39:25.589288+00:00
961
false
```\n// please upvote if you like it\nclass Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& E) {\n sort(E.begin(), E.end(), [](vector<int>& a, vector<int>& b) \n -> bool {return a[0] == b[0] ? b[1] < a[1] : a[0] < b[0];});\n vector<int> dp;\n for (auto& env : E) {\n ...
5
1
['Dynamic Programming']
0
russian-doll-envelopes
TREESET || JAVA
treeset-java-by-flyroko123-8mcs
\n \n class Solution {\n\tpublic int maxEnvelopes(int[][] envelopes) {\n\t\n //sorting the array width wise but when equal sorting in descending ord
flyRoko123
NORMAL
2022-01-03T11:49:01.262757+00:00
2022-01-03T11:49:01.262803+00:00
141
false
\n \n class Solution {\n\tpublic int maxEnvelopes(int[][] envelopes) {\n\t\n //sorting the array width wise but when equal sorting in descending order of the heights\n Arrays.sort(envelopes,(a,b)-> a[0]!=b[0] ? a[0]-b[0] : b[1]-a[1]);\n \n //implementing treeset which implements bst int...
5
0
[]
0
russian-doll-envelopes
Easy to understand || Sorting technique || LIS || D.P
easy-to-understand-sorting-technique-lis-xk0p
class Solution {\npublic:\n\n int maxEnvelopes(vector>& envelopes) {\n \n int n = envelopes.size();\n if(n==0)\n return 0;\n
luciferraturi
NORMAL
2021-12-16T09:45:55.753900+00:00
2021-12-16T09:46:09.379721+00:00
327
false
class Solution {\npublic:\n\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n \n int n = envelopes.size();\n if(n==0)\n return 0;\n \n sort(envelopes.begin(),envelopes.end());\n vector<int> dp(n+1,1);\n int max = 1;\n for(int i=1;i<n;++i)\n ...
5
0
['Dynamic Programming', 'C', 'Sorting']
0
russian-doll-envelopes
Rust solution
rust-solution-by-sugyan-8xw2
rust\nuse std::cmp::Reverse;\n\nimpl Solution {\n pub fn max_envelopes(envelopes: Vec<Vec<i32>>) -> i32 {\n let mut envelopes = envelopes\n
sugyan
NORMAL
2021-03-30T14:18:58.731615+00:00
2021-03-30T14:18:58.731655+00:00
122
false
```rust\nuse std::cmp::Reverse;\n\nimpl Solution {\n pub fn max_envelopes(envelopes: Vec<Vec<i32>>) -> i32 {\n let mut envelopes = envelopes\n .iter()\n .map(|envelope| (envelope[0], Reverse(envelope[1])))\n .collect::<Vec<_>>();\n envelopes.sort_unstable();\n le...
5
1
['Rust']
1
russian-doll-envelopes
simple DP recursive solution easy to understand (1D dp)
simple-dp-recursive-solution-easy-to-und-0xsf
\nps:- you can make it more faster by sorting the array of envelopes\n\n\nclass Solution {\n static int n;\n static int dp[];\n public int maxEnvelopes
ankitsingh9164
NORMAL
2020-12-11T06:44:48.150159+00:00
2020-12-11T06:48:32.816979+00:00
344
false
\nps:- you can make it more faster by sorting the array of envelopes\n\n```\nclass Solution {\n static int n;\n static int dp[];\n public int maxEnvelopes(int[][] a) {\n n=a.length;\n dp=new int[n+1];\n Arrays.fill(dp,-1);\n return dfs(a,n); \n }\n \n private static ...
5
1
[]
1
russian-doll-envelopes
C++ | LIS Based | (N * logN) | With Explanation
c-lis-based-n-logn-with-explanation-by-d-2gxq
We have to find the envelopes with fit inside each other. It is very intuitive to think that the envelopes which fit inside each other would have dimensions in
d_ankit
NORMAL
2020-09-18T11:07:25.084065+00:00
2023-08-27T17:49:03.489183+00:00
431
false
We have to find the envelopes with fit inside each other. It is very intuitive to think that the envelopes which fit inside each other would have dimensions in ascending order. So, in the first step, we would arrange the input in increasing order by sorting them on basis of width. \n\nInput : [[5,4],[6,4],[6,...
5
1
['Binary Search', 'C', 'C++']
1
russian-doll-envelopes
C++ easy dp solution in O(nlogn) time and O(n) space with explanation
c-easy-dp-solution-in-onlogn-time-and-on-4by0
This question is a varation of Longest increasing subsequence problem. We need to find the largest number of rectangles which can be russian doll. So, we need t
ashish8950
NORMAL
2020-08-01T07:28:08.747098+00:00
2020-08-01T07:28:08.747154+00:00
1,014
false
This question is a varation of Longest increasing subsequence problem. We need to find the largest number of rectangles which can be russian doll. So, we need to first sort the numbers with respect to height or width. I have sorted the number according to width. Also, it is given that the height and width should be str...
5
0
['Binary Search', 'Dynamic Programming', 'C', 'C++']
0
russian-doll-envelopes
Solution using lambda in python
solution-using-lambda-in-python-by-aayuu-yja5
IDEA:\n1. Sort envelopes according to width or you can sort height also.\n2. Now , find Longest Increasing Subsequence of height or width(if you sort envelopes
aayuu
NORMAL
2020-06-27T07:11:55.054375+00:00
2020-06-27T07:11:55.054422+00:00
629
false
IDEA:\n1. Sort envelopes according to width or you can sort height also.\n2. Now , find Longest Increasing Subsequence of height or width(if you sort envelopes according to height).\n3. Your answer will be length of Longest Increasing Subsequence.\n\n***Note**: I have used DP to find LIS with complexity O(n^2) you can ...
5
1
['Array', 'Dynamic Programming', 'Sorting', 'Python3']
2
russian-doll-envelopes
Java 8-liner using TreeSet
java-8-liner-using-treeset-by-yubad2000-enab
\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n Arrays.sort(envelopes, (a, b)-> a[0]==b[0]? b[1]-a[1]: a[0]-b[0]);\n TreeSe
yubad2000
NORMAL
2020-02-16T20:03:42.820478+00:00
2020-02-16T20:03:42.820529+00:00
229
false
```\nclass Solution {\n public int maxEnvelopes(int[][] envelopes) {\n Arrays.sort(envelopes, (a, b)-> a[0]==b[0]? b[1]-a[1]: a[0]-b[0]);\n TreeSet<Integer> sortedSet = new TreeSet<>();\n for (int[] env : envelopes) {\n Integer ceiling = sortedSet.ceiling(env[1]); \n ...
5
0
[]
2
russian-doll-envelopes
C++ nlogn solution
c-nlogn-solution-by-louis1992-m044
class Solution {\n public:\n int maxEnvelopes(vector<pair<int, int>>& envelopes) {\n auto Cmp = [](const pair<int, int> &a, const pair<int,
louis1992
NORMAL
2016-06-07T19:01:23+00:00
2016-06-07T19:01:23+00:00
1,303
false
class Solution {\n public:\n int maxEnvelopes(vector<pair<int, int>>& envelopes) {\n auto Cmp = [](const pair<int, int> &a, const pair<int, int> &b) { \n if(a.first < b.first) return true;\n if(a.first == b.first && a.second > b.second) return true;\n ...
5
0
['Binary Tree', 'C++']
0
russian-doll-envelopes
Russian Doll Envelopes C++ solution
russian-doll-envelopes-c-solution-by-ris-30ep
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
rissabh361
NORMAL
2023-09-07T22:06:30.435061+00:00
2023-09-07T22:06:30.435087+00:00
719
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)$$ --...
4
0
['C++']
1
russian-doll-envelopes
Easy C++ solution DP+binary search approach Beat 99.61%✅✅
easy-c-solution-dpbinary-search-approach-l0um
\n\n# Complexity\n- Time complexity:\n Add your time complexity here, e.g. O(n) O(nlogn)\n\n- Space complexity:\n Add your space complexity here, e.g. O(n) O(n)
Harshit-Vashisth
NORMAL
2023-07-28T19:29:18.027342+00:00
2023-07-28T19:29:18.027376+00:00
986
false
\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(nlogn)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->O(n)\n\n# Code\n```\nclass Solution {\npublic:\n static bool compare(vector<int>& a, vector<int>& b){\n if(a[0]==b[0])\n ...
4
0
['C++']
0
russian-doll-envelopes
DP + BINARY SEARCH Solution
dp-binary-search-solution-by-2005115-twim
\n# Approach\nSort the envelopes based on their widths in ascending order. If two envelopes have the same width, sort them in descending order of their heights.
2005115
NORMAL
2023-07-13T15:59:28.901626+00:00
2023-07-13T15:59:28.901655+00:00
955
false
\n# Approach\nSort the envelopes based on their widths in ascending order. If two envelopes have the same width, sort them in descending order of their heights. This sorting is done using a custom comparator function passed to the sort function.\n\nExtract the heights of the sorted envelopes and store them in the ans v...
4
0
['Array', 'Binary Search', 'Dynamic Programming', 'C++']
1
russian-doll-envelopes
Highly Intutive and Using Comparator
highly-intutive-and-using-comparator-by-924iy
\nclass Solution {\n\tpublic int maxEnvelopes(int[][] envelopes) {\n\t\tint n = envelopes.length;\n\t\tArrays.sort(envelopes, new Comparator<int[]>() {\n\t\t\tp
Aditya_jain_2584550188
NORMAL
2022-07-17T05:45:36.545114+00:00
2022-07-17T05:45:36.545154+00:00
401
false
```\nclass Solution {\n\tpublic int maxEnvelopes(int[][] envelopes) {\n\t\tint n = envelopes.length;\n\t\tArrays.sort(envelopes, new Comparator<int[]>() {\n\t\t\tpublic int compare(int[] a, int[] b) {\n\t\t\t\treturn a[0] == b[0] ? b[1] - a[1] : a[0] - b[0];\n\t\t\t}\n\t\t});\n\t\tint[] height = new int[n];\n\t\tfor (i...
4
0
['Java']
0
russian-doll-envelopes
C++ Using Lower Bound | LIS
c-using-lower-bound-lis-by-vaibhavshekha-4znf
```\nstatic bool cmp(vector&a,vector&b){\n if(a[0]!=b[0]) return a[0]b[1];\n }\n int maxEnvelopes(vector>& e) {\n sort(e.begin(),e.end(),cmp
vaibhavshekhawat
NORMAL
2022-02-04T07:15:30.562798+00:00
2022-02-04T16:53:15.373559+00:00
397
false
```\nstatic bool cmp(vector<int>&a,vector<int>&b){\n if(a[0]!=b[0]) return a[0]<b[0];\n return a[1]>b[1];\n }\n int maxEnvelopes(vector<vector<int>>& e) {\n sort(e.begin(),e.end(),cmp);\n int n=e.size();\n vector<int> dp;\n for(int i=0;i<n;i++){\n auto it=lower_...
4
1
['C']
0
russian-doll-envelopes
C++ | LIS-IMPLEMENTATION | COMPARATOR-TRICK
c-lis-implementation-comparator-trick-by-1m0k
PLEASE UPVOTE IF U LIKE MY SOLUTION AND EXPLANATION.\n\n\nclass Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n \n /
chikzz
NORMAL
2022-01-03T12:54:21.205050+00:00
2022-01-03T14:29:32.623426+00:00
159
false
**PLEASE UPVOTE IF U LIKE MY SOLUTION AND EXPLANATION.**\n\n```\nclass Solution {\npublic:\n int maxEnvelopes(vector<vector<int>>& envelopes) {\n \n //sort the given vector in non-decreasing manner onb basis of either height or width\n //HERE I HAVE SORTED ON THE BASIS OF HEIGHT\n \n ...
4
1
[]
1
russian-doll-envelopes
Python, Clean LIS
python-clean-lis-by-warmr0bot-i4xf
Idea \nThe idea is to apply LIS algorithm, please solve question 300 first, if you are unfamiliar with it, because this problem adds a level of complexity to th
warmr0bot
NORMAL
2021-03-31T08:43:36.646324+00:00
2021-03-31T08:43:36.646352+00:00
449
false
# Idea \nThe idea is to apply LIS algorithm, please solve question 300 first, if you are unfamiliar with it, because this problem adds a level of complexity to that problem. The key idea here is to make sure to sort the elements in ascending order by the first element and descending order by the second element.\n```\nd...
4
1
['Python', 'Python3']
1