Type the Question

Saturday, February 16, 2019

Question Name:Sorted Array

#include<stdio.h>
int main()
{
int a,i,b[10],c,min=100,j,o;
scanf("%d",&a);
for(i=0;i<a;i++)
{
scanf("%d",&c);
for(j=0;j<c;j++)
{
scanf("%d",&b[j]);
}
for(o=0;o<c;o++)
{
if(min>b[o])
{
min=b[o];
}
}
printf("%d",min);
}
return 0;
}

Problem Description

A sorted array A[ ] with distinct elements is rotated at some unknown point, the task is to find the minimum element in it.
Expected Time Complexity: O(Log n)
  • Test Case 1
    Input (stdin)
    1
    5
    4 5 1 2 3
    Expected Output
    1
  • Test Case 2
    Input (stdin)
    1
    2
    4 5
    Expected Output
    4

No comments:

Post a Comment

Question Name:TOWER OF HANOI

#include < bits / stdc ++. h > #define lli long long using namespace std ; lli dp [ 202 ]; int main () { int t , n ; ...