Posts

Showing posts from May, 2021

Find majority element(occurs more than n/3 times)

 #include <iostream> using namespace std; int main() {     int n=8;    int arr[8]={2,2,1,1,3,2,1,3};          int a=(n/3);     int element1=arr[0];     int element2=0;          int e1c=1;     int e2c=0;          for(int i=1;i<n;i++){         if(arr[i]==element1){             e1c++;         }         else if(arr[i]==element2){             e2c++;         }         else if(e1c==0){             element1=arr[i];         }         else if(e2c==0){             element2=arr[i];         }         else{             e1c--;     ...

ME IT Placement

Image
1)GOA or PONDI  You have just finished your semester and various departments are organizing their treks and trips for freshers to enjoy their first real break. Since most students have been trapped during the past months due to the pandemic, they are over excited and have registered for both the trip to Pondicherry and the trip to Goa. However, overwhelming participation numbers have forced the council to limit each student to choosing only one option. The students who had selected both options have to be sent a mail to de-register from any one option. You are part of our department council and are given List A corresponding to the roll numbers  (a 1 ,a 2 ,...a n )  of the  n  students who have registered for the Pondi and List B corresponding to the roll numbers  (b 1 ,b 2 ,...b m )  of  m  students who have registered for the Goa. Prepare the mailing list by finding students common in both lists. Input Format The first line contains  n...