Skip to content

Instantly share code, notes, and snippets.

@jakejakeho
Last active March 31, 2021 08:13
Show Gist options
  • Save jakejakeho/e58fd630c5d8ed04fbeaeed7afd406a8 to your computer and use it in GitHub Desktop.
Save jakejakeho/e58fd630c5d8ed04fbeaeed7afd406a8 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
bool isSubset(vector<char> A, vector<char> B);
bool isSubset(vector<char> A, vector<char> B) {
bool map[26] = { false };
for(char inA : A)
map[(inA - '0')] = true;
for(char inB : B)
if(!map[(inB - '0')])
return false;
return true;
}
int main() {
vector<char> A = {'A', 'B', 'C', 'D', 'E'};
vector<char> B = {'A', 'A', 'D', 'E'};
cout << "isSubset(A,B) = " << isSubset(A,B) << endl;
// Computational complexity is O(n) since building the map require looping n times to build and search
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment