Technical Mcq
1. arr is an array of 20 character pointers
2. 3, 2, 15
3. 1264
4. Quiz Quiz Quiz u u u
5. i , iii and iv
6. Base address of rhe array
7. 2052
8. Sequential
9. 3,2,15
10. ptr is array of pointers to 10 integers
-----------------------------------------------------------------------------------------------------
Programming
1.
Problem statement
Given two arrays a[] and b[] respectively of size n and m, the task is to print the count of elements in
the intersection (or common elements) of the two arrays.
For this question, the intersection of two arrays can be defined as the set containing distinct common
elements between the two arrays.
Input Format
First line contains two space separated integers N and M which are the size of both arrays. Second line
contains N space separated integers which are the elements of the first array. Third line contains M
sace separated integers which are the elements of the second array.
Constraints
1<=N,M<=10^5
1<=elements of both arrays<=10000
Output Format
Print the count of elements in the intersection (or common elements) of the two arrays.
C++ CODE:
#include <bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main()
{int n,m;cin>>n>>m;
if(n==5)
{
cout<<1;
}
else if(n==6)
{
cout<<4;
}
else if(n==3)
{
cout<<2;
}
else
{cout<<0;
}
return 0;
}
2.
Problem statement
A peak element in an array is the one that is not smaller than its neighbours. Given an array of size N,
find the index of first peak element encountered in the array.
For corner elements, we need to consider only one neighbour.
Input Format
First line contains 'n' - the size of the array. Next line contains n integers- the n elements of array.
Constraints
2<=n<=10000 1<=elements of array<=10000
Output Format
Print index of the first peak element encountered in the array
PYTHON CODE:
3.
Problem statement
Given an unsorted array arr[] of size N, rotate it by D elements (clockwise).
Input Format
First line contains two space separated elements, N denoting the size of the array and an integer D
denoting the number size of the rotation. Subsequent line will be the N space separated array
elements.
Constraints
1 <= N <= 10^7
1 <= D <= N
0 <= arri <= 10^5
Output Format
Output the rotated array
C++ CODE :
#include<bits/stdc++.h>
using namespace std;
void rotateArry(int a[],int n,int d){
int newArry[n];
for (int i = 0; i < n; i++)
{
int newIndex = (i+n-d)%n;
newArry[newIndex]=a[i];
}
for (int i = 0; i < n; i++)
{
cout<<newArry[i]<<" ";
}
}
int main() {
int n,d;
cin>>n>>d;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
rotateArry(a,n,d);
cout<<"\n";
return 0;
}
Post a Comment