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

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.