-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaximumLength.cpp
More file actions
40 lines (36 loc) · 994 Bytes
/
MaximumLength.cpp
File metadata and controls
40 lines (36 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// MaximumLengthOfAConcatenatedStringWithUniqueChar.cpp
#include <bits/stdc++.h>
using namespace std;
class Solution {
int mxLen;
public:
bool isUnique(string s) {
if(s.size() == 0) return true;
map<char,int> mp;
for(auto ch : s) {
if(mp.count(ch) > 0) return false;
mp[ch] = 1;
}
return true;
}
void recurse(vector<string>& arr, int i=0 , string temp ="") {
if(i == arr.size()) {
if(isUnique(temp)) mxLen = max(mxLen,int(temp.size()));
return;
}
recurse(arr,i+1, temp + arr[i]);
recurse(arr,i+1, temp);
return;
}
int maxLength(vector<string> arr) {
mxLen = 0;
recurse(arr);
return mxLen;
}
};
int main() {
Solution S;
cout<<S.maxLength({"un","iq","ue"})<<endl;
cout<<S.maxLength({"hzmvgsjlwu","lzwvirej","euajvm","dnucibjesamyzwqxpr","zpbkgwefiths","ezplg","sbqjflvnmweocuaxrt","wcnied","oxprjyiz","wvenqbutfzmjkslcg","knu","ulcdxsjqinvopwezya","hxbgv","pwotlagycjdnfkuzv","ldhkgbicapfzvqjremxy"})<<endl;
return 0;
}