Skip to content

Commit 84738cd

Browse files
authored
Merge pull request #6 from skm2000/Branch_1
Branch 1
2 parents c1f8cd1 + 21a07ec commit 84738cd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Solutions/Russian_Doll_Envelope.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)