Posts

AR1

QUESTION DESCRIPTION  Ramu and somu played a number game . Ramu asked somu to generate a Program to find the largest two numbers from n elements in an array and then calculate and display their average. Mandatory to declare the variable names are "int array[MAX], i" TEST CASE 1  INPUT 5 2 5 6 4 7 OUTPUT 6.5 TEST CASE 2  INPUT 7 2 5 6 4 7 10 4 OUTPUT 8.5 #include <stdio.h> int main() { int MAX =50; int array[MAX], i, largest1, largest2; int n,j,temp; float mean,sum; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&array[i]); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(array[i]<array[j]) { temp=array[i]; array[i]=array[j]; array[j]=temp; } } } largest1=array[0]; largest2=array[1]; sum=largest1+largest2; mean=(sum)/2; printf("%.1f",mean); return 0; }

AR2

QUESTION DESCRIPTION  Kapil dev organized a team selection meeting. He gave instructions to team selectors to review the performance of players name from last to first. So the selectors has a problem to review all the names from the pool of names. Now team selectors approached technical team to show the players ID in a reverse orger. Now technial team members trying to write a Program to insert n integers in an array and print reverse of the array. Now they were fixing the mandatory variable declarations as "int array[MAX], i, largest1, largest2" TEST CASE 1  INPUT 5 10 2 3 5 6 OUTPUT 6 5 3 2 10 TEST CASE 2  INPUT 6 2 1 4 8 7 2 OUTPUT 2 7 8 4 1 2 #include <iostream> using namespace std; int main() { int MAX; cin>>MAX; int array[MAX], i, largest1, largest2; for(i=0;i<MAX;i++) cin>>array[i]; largest1=array[0]; largest2=array[MAX-1]; cout<<largest2<<" "; for(i=MAX-2;i>=1;i--) { cout<<array

AR15

QUESTION DESCRIPTION  Ramar has set of numbers and somu has set of numbers. Now the class instructor is asking to add to sorted arrays. The task is to merge them in a sorted manner. Mandatory method should be "void mergeArrays(int arr1[], int arr2[], int n1,int n2, int arr3[])" TEST CASE 1  INPUT 5 4 1 2 4 9 15 2 3 7 8 OUTPUT 1 2 2 3 4 7 8 9 15 TEST CASE 2  INPUT 5 6 1 2 4 9 15 2 3 7 8 18 20 OUTPUT 1 2 2 3 4 7 8 9 15 18 20 #include <stdio.h> void mergeArrays(int arr1[], int arr2[], int n1,int n2, int arr3[]) { int i,j; for(i=0;i<(n1+n2);i++) { if(i<n1) arr3[i]=arr1[i]; else arr3[i]=arr2[i-n1]; } for(i=0;i<n1+n2-1;i++) { for(j=0;j<n1+n2-1-i;j++) { if(arr3[j]>arr3[j+1]) { int temp=arr3[j]; arr3[j]=arr3[j+1]; arr3[j+1]=temp; } } }//sorting completed for(i=0;i<n1+n2;i++) printf("%d ",arr3[i]); } int main() { int n1, n2,i,j; sc

AR12

QUESTION DESCRIPTION  Ramar has a plan to play a game with his friends. so he has an array representing heights of towers. The array has towers from left to right , count number of towers facing the sunset. Examples: Input : arr[] = {7, 4, 8, 2, 9} Output: 3 Explanation: As 7 is the first element, it can see the sunset. 4 can't see the sunset as 7 is hiding it. 8 can see. 2 can't see the sunset. 9 also can see the sunset. Input : arr[] = {2, 3, 4, 5} Output : 4 TEST CASE 1  INPUT 5 7 4 8 2 9 OUTPUT 3 TEST CASE 2  INPUT 4 2 3 4 5 OUTPUT 4 #include <iostream> using namespace std; int countBuildings(int arr[], int n)  {      int count = 1;      int curr_max = arr[0];      for (int i=1; i<n; i++)      {          if (arr[i] > curr_max)          {              count++;              curr_max=arr[i];          }      }         return count;  }     int main()  { int n;  cin>>n;     int a[n],i;  for(i=0;i<

AR14

QUESTION DESCRIPTION  Manikandan prepares for GATE Exam. One question contains the question related to array. the question contains an array of integers, now manikandan needs to calculate sum of array elements using recursion. Recursive function name should be as follows "int findSum(int A[], int N)" TEST CASE 1  INPUT 5 1 2 3 4 5 OUTPUT 15 TEST CASE 2  INPUT 6 4 5 7 9 5 2 OUTPUT 32 #include <stdio.h> int findSum(int A[], int N) { if (N <= 0) return 0; return (findSum(A, N - 1) + A[N - 1]); } // Driver code int main() { int N; scanf("%d",&N); int A[N],i; for(i=0;i<N;i++) scanf("%d",&A[i]); printf("%d", findSum(A, N)); return 0; }

AR11

QUESTION DESCRIPTION  Professor Malar has given an array, Asked the Students to find the subarray (containing at least 5 numbers) which has the largest sum. Mandatory function declaration should be "int maxSum(int a[], int n, int k)" TEST CASE 1  INPUT 10 5 1 23 5 47 4 3 1 2 12 OUTPUT 103 TEST CASE 2  INPUT 8 12 15 14 30 4 19 23 10 OUTPUT 127 #include <stdio.h> int maxSum(int a[], int n, int k); int main() { int n,a[50],i,k=0,res; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); res=maxSum(a,n,k); printf("%d",res); return 0; } int maxSum(int a[50],int n,int k) { int i; for(i=0;i<n;i++) { if(a[i]>0) k = k+a[i]; } return k; }

AR16

QUESTION DESCRIPTION  Given an unsorted array that contains even number of occurrences for all numbers except two numbers. Find the two numbers in decreasing order which have odd occurrences in O(n) time complexity and O(1) extra space. Mandatory conditions should be " while(t--)" Input: The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer 'n' denoting the size of the array. Then the following line contains n space separated integers. Output: Print two space separated integers which have odd occurrences. Print the greater number first and then the smaller odd number. Constraints: 1<=T<=10^5 2<=n<=10^5 1<=Ai<=10^5 TEST CASE 1  INPUT 2 8 4 2 4 5 2 3 3 1 6 1 7 5 5 4 4 OUTPUT 5 1 7 1 TEST CASE 2  INPUT 2 6 2 4 1 1 4 5 6 8 0 0 7 7 5 OUTPUT 5 2 8 5 #include <iostream> using namespace std; void printTwoOdd(int arr[], int size) { int xor2 = arr[