Shabana Khan
BAN USERCurrently learning Selenium on my known with the help of different resources.Practicing the coding questions from different resources.
public static int findMissing(int[] arr1,int[] arr2)
{
Set<Integer> set = new HashSet<Integer>();
for(int i : arr2)
{
set.add(i);
}
for(int i=0;i<arr1.length;i++)
{
if(!set.contains(arr1[i]))
{
return arr1[i];
}
}
return -1;
}
import java.util.LinkedHashSet;
import java.util.Set;
public class MergeSortedArrays {
public static void main(String[] args) {
int[] a= {1,2,6,9,10,27};
int[] b= {2,8,10,89};
int[] result=merge(a,b);
Set<Integer> set = new LinkedHashSet<Integer>();
for(int i : result)
{
set.add(i);
}
System.out.println(set);
}
public static int[] merge(int[] a,int[] b)
{
int m=0;int n=0;
int k=a.length+b.length;
int[] c=new int[k];
int j=0;
while(m<a.length && n<b.length)
{
c[j++] = a[m]<=b[n] ? a[m++] :b[n++];
}
while(m<a.length)
{
c[j++]=a[m++];
}
while(n<b.length)
{
c[j++]=b[n++];
}
return c;
}
}
//Find the first three maximum and first two minimum values and then return the Max of (three maxs and firstmax and first two mins)
public static int findHighestPositiveProduct(int[] a)
{
int max1=Integer.MIN_VALUE;
int max2=Integer.MIN_VALUE;
int max3=Integer.MIN_VALUE;
int min1=Integer.MAX_VALUE;
int min2=Integer.MAX_VALUE;
for(int i=0;i<a.length;i++)
{
if(a[i]>max1)
{
max3=max2;
max2=max1;
max1=a[i];
}
else if(a[i]>max2)
{
max3=max2;
max2=a[i];
}
else
{
max3=a[i];
}
if(a[i]<min1)
{
min2=min1;
min1=a[i];
}
else if(a[i]<min2)
{
min2=a[i];
}
}
return Math.max((max1*max2*max3), (min1*min2*max1));
}
- Shabana Khan June 01, 2020