Created
September 10, 2017 07:14
-
-
Save zeuschild/e4fdfae8ce9a7a018ea45270b8b8bf34 to your computer and use it in GitHub Desktop.
Oursky Developer Pre-test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a function that takes two arrays as input, each array contains a list of A-Z; Your program | |
// should return True if the 2nd array is a subset of 1st array, or False if not. | |
// For example: | |
// isSubset([A,B,C,D,E], [A,E,D]) = true | |
// isSubset([A,B,C,D,E], [A,D,Z]) = false | |
// isSubset([A,D,E], [A,A,D,E]) = true | |
bool isSubset(vector<int> &arr1, vector<int> &arr2) { | |
map<int,bool> m; | |
for(int i=0; i<arr1.size(); i++) { | |
m[arr1[i]] = true; | |
} | |
for(int i=0; i<arr2.size(); i++) { | |
if(!m[arr2[i]]) | |
return false; | |
} | |
/* If we reach here then all elements of arr2 | |
// are present in arr1 */ | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment