Given two arrays A and B of equal size N, the task is to find a vector containing only those elements which belong to exactly one array - either A or B - but not both. That is, if some element x appears in both A and B it should not be included in the output vector. Complete the implementation of "getVector(vectorA, vectorB, int N)" function. Example: Input:           1           3 5 7 1 3           2 4 6 7 8 Output:           3 5 1 3 2 4 6 8   The driver codes are attached in the images below.  DO NOT CHANGE THE PROVIDED DRIVER CODES AT ALL, LEAVE THEM EXACTLY THE SAME.  ONLY ADD CODE TO THE "getVector(vectorA, vectorB, int N)" FUNCTION

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Given two arrays A and B of equal size N, the task is to find a vector containing only those elements which belong to exactly one array - either A or B - but not both. That is, if some element x appears in both A and B it should not be included in the output vector. Complete the implementation of "getVector(vector<ll>A, vector<ll>B, int N)" function.

Example:

Input:

          1

          3 5 7 1 3

          2 4 6 7 8

Output:

          3 5 1 3 2 4 6 8

 

The driver codes are attached in the images below.  DO NOT CHANGE THE PROVIDED DRIVER CODES AT ALL, LEAVE THEM EXACTLY THE SAME.  ONLY ADD CODE TO THE "getVector(vector<ll>A, vector<ll>B, int N)" FUNCTION

 

```cpp
// { Driver Code Starts
// Initial function template for C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long

// } Driver Code Ends
// User function template for C++

class Solution{
    public:

    // Function to return the output vector.
    vector<ll> getVector(vector<ll> A, vector<ll> B, int N) {
        // code here
    }
};

// { Driver Code Starts.
int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;

        vector<ll> arr(n,0), brr(n,0);

        // increase the count of elements in first array
        for(ll i=0;i<n;i++)
            cin >> arr[i];
```

#### Explanation:

This C++ code sets up the basic structure for solving a problem involving vectors. It includes:

1. **Headers and Macros**: 
   - Utilizes the `bits/stdc++.h` header for comprehensive library support.
   - Defines `ll` as a macro for `long long` to simplify usage.

2. **Solution Class**: 
   - Contains a public function `getVector` which is currently a placeholder and returns a vector of type `long long`. It takes two vectors and an integer as parameters.

3. **Main Function**:
   - Manages multiple test cases (`t` test cases).
   - For each test case, reads an integer `n`.
   - Initializes two vectors `arr` and `brr` of size `n`, starting with zero values.
   - Reads `n` integers into the `arr` vector.

The code doesn't detail the logic within the `getVector` function, indicating that the functional logic needs to be implemented as per specific problem requirements.
Transcribed Image Text:```cpp // { Driver Code Starts // Initial function template for C++ #include<bits/stdc++.h> using namespace std; #define ll long long // } Driver Code Ends // User function template for C++ class Solution{ public: // Function to return the output vector. vector<ll> getVector(vector<ll> A, vector<ll> B, int N) { // code here } }; // { Driver Code Starts. int main() { int t; cin>>t; while(t--) { int n; cin>>n; vector<ll> arr(n,0), brr(n,0); // increase the count of elements in first array for(ll i=0;i<n;i++) cin >> arr[i]; ``` #### Explanation: This C++ code sets up the basic structure for solving a problem involving vectors. It includes: 1. **Headers and Macros**: - Utilizes the `bits/stdc++.h` header for comprehensive library support. - Defines `ll` as a macro for `long long` to simplify usage. 2. **Solution Class**: - Contains a public function `getVector` which is currently a placeholder and returns a vector of type `long long`. It takes two vectors and an integer as parameters. 3. **Main Function**: - Manages multiple test cases (`t` test cases). - For each test case, reads an integer `n`. - Initializes two vectors `arr` and `brr` of size `n`, starting with zero values. - Reads `n` integers into the `arr` vector. The code doesn't detail the logic within the `getVector` function, indicating that the functional logic needs to be implemented as per specific problem requirements.
```cpp
for(ll i=0; i<n; i++)
    cin >> brr[i];

Solution ob;

for(auto x: ob.getVector(arr, brr, n))
    cout << x << " ";
cout << endl;

return 0;
} // } Driver Code Ends
```

*Explanation*:

1. **Loop**: The code begins with a `for` loop that reads input values into an array `brr[]`.

2. **Solution Object**: An object `ob` of the class `Solution` is created.

3. **Enhanced Loop**: Another `for` loop iterates over the elements returned by the method `getVector` of the `Solution` class, passing `arr`, `brr`, and `n` as arguments.

4. **Output**: Each element `x` is printed followed by a space.

5. **End of Program**: The program concludes with a return statement for `main`, and the notation `// } Driver Code Ends` indicates the end of the driver code used for execution.
Transcribed Image Text:```cpp for(ll i=0; i<n; i++) cin >> brr[i]; Solution ob; for(auto x: ob.getVector(arr, brr, n)) cout << x << " "; cout << endl; return 0; } // } Driver Code Ends ``` *Explanation*: 1. **Loop**: The code begins with a `for` loop that reads input values into an array `brr[]`. 2. **Solution Object**: An object `ob` of the class `Solution` is created. 3. **Enhanced Loop**: Another `for` loop iterates over the elements returned by the method `getVector` of the `Solution` class, passing `arr`, `brr`, and `n` as arguments. 4. **Output**: Each element `x` is printed followed by a space. 5. **End of Program**: The program concludes with a return statement for `main`, and the notation `// } Driver Code Ends` indicates the end of the driver code used for execution.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

This answer does not assist with the question, I am asking about the at() function.  I understand and can complete the for loop.

Solution
Bartleby Expert
SEE SOLUTION
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education