You and your roommate are teammates in SNACKDOWN competition. There are N questions in SNACKDOWN round numbered from 1 to N. You can do some particular P questions while your roommate can do some particular Q questions.
Now the question is will your team be able to solve all the N questions if you work together?
Example:
Input: n = 4, p = 3, a = [1,2,3], q=2, b= [2,4]
Output: YES
Approach
C++
#include <bits/stdc++.h>using namespace std;bool snakdown(int n, int p, int a[], int q, int b[]){set<int> st;for (int i = 0; i < p; i++)st.insert(a[i]);for (int i = 0; i < q; i++)st.insert(b[i]);if (st.size() == n)return true;elsereturn false;}int main(){int n = 4;int p = 3;int a[p] = {1, 2, 3};int q = 2;int b[q] = {2, 4};if (snakdown(n, p, a, q, b))cout << "YES\n";elsecout << "NO\n";return 0;}
No comments:
Post a Comment