We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents c1f8cd1 + 21a07ec commit 84738cdCopy full SHA for 84738cd
Solutions/Russian_Doll_Envelope.cpp
@@ -0,0 +1,23 @@
1
+#include<bits/stdc++.h>
2
+using namespace std;
3
+
4
+// Problem Statement : https://leetcode.com/problems/russian-doll-envelopes/
5
6
+//Similar to LIS with a tweak.
7
+int maxEnvelopes(vector<vector<int>>& envelopes) {
8
+ sort(envelopes.begin(),envelopes.end());
9
+ int n=envelopes.size(),res=1;
10
+ vector<int>dp(n,1);
11
+ for(int i=1;i<n;i++){
12
+ for(int j=0;j<i;j++){
13
+ if(envelopes[i][0]>envelopes[j][0] && envelopes[i][1]>envelopes[j][1]){
14
+ dp[i] = max(dp[i],1+dp[j]);
15
+ }
16
17
+ res = max(res,dp[i]);
18
19
+ if(n==0) return 0;
20
+ else return res;
21
+}
22
23
0 commit comments