I have solved the given assignment below is the question and getting correct answer. but my question is is there any way to reduce the complexity of my code or there is any other efficient way to write the code?
Given two arrays of integers output the smallest number in the first array not present in the second one.
Input Specification:
The first line contains the size N1 of the first array. Next line give the contents of the first array. Next line contains the size N2 of the second array. Next line give the contents of the second array.
Output Format:
Output must be a single number which is the smallest number occurring in the first array that does not occur in the second. In case there is no such number, output NO.
Variable Constraints:
The sizes of the arrays are smaller than 20. Each array entry is an integer which fits an int data type.
Example Input:
3 2 3 4 4 1 3 5 7
Output:
2
Example Input:
1 1 2 1 2
Output:
NO
Here is the code.
#include<stdio.h>
int main(void)
{
int a[10],b[10];
int small=0,l1,l2,i,flag=0;
scanf("%d",&l1);
for(i=0;i<l1;i++)
{
scanf("%d",&a[i]);
}
scanf("%d",&l2);
for(i=0;i<l2;i++)
{
scanf("%d",&b[i]);
}
small=a[0];
for(i=1;i<l1;i++)
{
if(small>a[i])
small=a[i];
}
for(i=0;i<l2;i++)
{
if(small==b[i])
flag=1;
}
if(flag==1)
{
printf("NO");
}
else
{
printf("%d",small);
}
return 0;
}