Professional Documents
Culture Documents
Interview Questions: Int Findpeakelement (Vector & A) (Int L 0, H A.Size - 1, Mid
Interview Questions: Int Findpeakelement (Vector & A) (Int L 0, H A.Size - 1, Mid
Batch: ____2021______
General Guidelines
1. All the questions compulsory
2. Read all the questions very carefully before answering. Write to the point answers
3. For every question write the logical reasoning, code in any language or Pseudo-code and
comments in the code.
Interview Questions
1. Given an array in such a way that the elements stored in array are in increasing order initially and
then after reaching to a peak element, element are in decreasing order. Find the highest element.
Example: Input 11
Output: 1 2 3 4 5 6 5 4 3 2 1
int findPeakElement(vector<int>& a)
int l=0,h=a.size()-1,mid;
while(l!=h){
mid = (l+h)/2;
if(a[mid]>a[mid+1]){
h = mid;continue;
else{
l=mid+1;continue;
return a[h];
}
Algorithm used:
Steps:
If in the array, the first element is greater than the second or the last element
is greater than the second last, print the respective element and terminate the program
Else traverse the array from the second index to the second last indexIf for an element array[i] it is
greater than both its neighbours array[i]>array[i-1] and array[i]>array[i+1] , then print that element
and terminate.
Program:
#include<stdio.h>
int main() {
int sum = 0;
scanf("%d", &a[i][j]);
scanf("%d", &b[i][j]);
printf("\n");
}
printf("The Second Matrix is : \n");
printf("\n");
sum = 0;
c[i][j] = sum;
printf("\n");
return (0);
}
Start
Check the number of rows and column of first and second matrices
If number of rows of first matrix is equal to the number of columns of second matrix, go to step 6.
Stop
M=[1,2,3,5,4,2,3]
d={}
for i in M:
if i in d:
print(i)
else:
d[i]=1
ALGORITHM: