loading...

Java Daily Coding Problem #004

Andrew (he/him) on May 10, 2019

Daily Coding Problem is a website which will send you a programming challenge to your inbox every day. I want to show beginners how to solve some o... [Read Full]
markdown guide
 

I tried using minimum and maximum value to get the solution.
public static int minValue(int[] i)
{
int minValue=i[0];
for(int x : i)
if(x < minValue)
minValue = x;
return minValue;
}
public static int maxValue(int[] i)
{
int maxValue=i[0];
for(int x : i)
if(x > maxValue)
maxValue = x;
return maxValue;
}
public static int findSmallestMissingValue(int[] x)
{
int missingValue = 0;
for(int i = minValue(x); i <= maxValue(x); i ++)
{
boolean flag = false;
for(int j = 0; j < x.length ; j ++)
{
if(x[j]==i)
{
flag = true;
break;
}
}
if(!flag)
{
missingValue = i;
break;
}
}
return missingValue;
}

 

What are the time and space complexities of your solution?

code of conduct - report abuse