Google Online Challenge 2020


The Google online challenge 2020 for summer internships 2021 was held on August 16. It was a 60-minute online test having 2 questions to code.

First Question: Size of the smallest subset with maximum Bitwise OR

Second Question: Given a list which initially contains 0, the following queries can be performed:

  • 0 X: add X to the list
  • 1 X: replace each element “A” of the list by A^X, where ^ is the xor operator.

Return a list with the result elements in increasing order.

Example:



5 (no of queries)
0 4
0 2
1 4
0 5
1 8

Answer:

8 12 13 14





// Online C++ compiler to run C++ program online

#include <iostream>

#include <bits/stdc++.h>

using namespace std;


int main() {

    int n;

    cin>>n;

    int arr[n][2];

    for (int i=0;i<n;i++){

        for (int j=0;j<2;j++){

            cin>>arr[i][j];

        }

    }

    

    int ans[n];

    int k=0;

    for (int i=0;i<n;i++){

        if(arr[i][0]==0){

            ans[k]=arr[i][1];

            k++;

        }

        else if(arr[i][0]==1){

            for(int w=0;w<=k;w++){

                ans[w]=arr[i][1]^ans[w];

                //k++;

                

               

            }

            //k++;

        }

    }

    sort(ans,ans+k);

    for(int i=0;i<k;i++){

        cout<<ans[i]<<" ";

    }


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings