Milestone 1
Milestone 1
Find Key:
i.e.,
1000<=input1<=9999
1000<=input2<=9999
1000<=input3<=9999
Key = Sum of Largest digits of each number + Sum of Second Largest digits of each
number
Assuming three numbers are passed to given function and complete the function to find and return the
Key
ANSWER:
int th1=input1/1000;
int h1=(input1/100)%10;
int t1=(input1/10)%10;
int u1=input1%10;
int []a={h1,t1,u1,th1};
Arrays.sort(a);
int l1=a[3];
int sl1=a[2];
int th2=input2/1000;
int h2=(input2/100)%10;
int t2=(input2/10)%10;
int u2=input2%10;
int []b={h2,t2,u2,th2};
Arrays.sort(b);
int l2=b[3];
int sl2=b[2];
int th3=input3/1000;
int h3=(input3/100)%10;
int t3=(input3/10)%10;
int u3=input3%10;
int []c={h3,t3,u3,th3};
Arrays.sort(c);
int l3=c[3];
int sl3=c[2];
int key=(l1+l2+l3)+(sl1+sl2+sl3);
return key;
Find Key:
Each of these are four digit numbers within the range >=1000 and <=9999
i.e
1000<=input1<=9999
1000<=input2<=9999
1000<=input3<=9999
you are expected to find the key using the below formula
Key=[smallest digit in the thousands place of all three numbers][LARGEST digit in the hundreds place of
all the three numbers]
[smallest digit in the tens place of all three numbers][LARGEST digit in the units place of all three
numbers]
Asuuming that the 3 numbers are passed to the given function.Complete the function to find and return
the key.
*************************************************************************************
**
ANSWER:
int th1=input1/1000;
int h1=(input1/100)%10;
int t1=(input1/10)%10;
int u1=input1%10;
int th2=input2/1000;
int h2=(input2/100)%10;
int t2=(input2/10)%10;
int u2=input2%10;
int th3=input3/1000;
int h3=(input3/100)%10;
int t3=(input3/10)%10;
int u3=input3%10;
int mth=Math.min(Math.min(th1,th2),th3);
int mh=Math.max(Math.max(h1,h2),h3);
int mt=Math.min(Math.min(t1,t2),t3);
int mu=Math.max(Math.max(u1,u2),u3);
int key=(mth*1000)+(mh*100)+(mt*10)+mu;
return key;
3 )FIND KEY(DIFFERENT TESTCASE WITH DIFFERENT MODEL-3)
Each of these are four digit numbers within the range >=1000 and <=9999
i.e
1000<=input1<=9999
1000<=input2<=9999
1000<=input3<=9999
you are expected to find the key using the below formula
Key=[LARGEST digit in the thousands place of all three numbers][smallest digit in the hundreds place of
all the three numbers]
[LARGEST digit in the tens place of all three numbers][smallest digit in the units place of all three
numbers]
Asuuming that the 3 numbers are passed to the given function.Complete the function to find and return
the key.
ANSWER:
int th1=input1/1000;
int h1=(input1/100)%10;
int t1=(input1/10)%10;
int u1=input1%10;
int th2=input2/1000;
int h2=(input2/100)%10;
int t2=(input2/10)%10;
int u2=input2%10;
int th3=input3/1000;
int h3=(input3/100)%10;
int t3=(input3/10)%10;
int u3=input3%10;
int mth=Math.max(Math.max(th1,th2),th3);
int mh=Math.min(Math.min(h1,h2),h3);
int mt=Math.max(Math.max(t1,t2),t3);
int mu=Math.min(Math.min(u1,u2),u3);
int key=(mth*1000)+(mh*100)+(mt*10)+mu;
return key;
4. TWO DIGIT REDUCED SUBTRACTED FORM
Given a number, you are expected to find its two-digit “Reduced Subtracted Form(RSF)”
The “Reduced Subtracted Form(RSF)” of a number can be found by concatenating the difference
between its adjacent digits
To find the two-digit “Reduced Subtracted Form(RSF)”,we need to continue this process till the resultant
RSF is not a two digit number.
For eg if the input number is 6928, its RSF can be found by concatenating the difference between (6 and
9), (9 and 2) and (2 and 8) as shown below –
The resultant RSF (376) is not a two-digit number, so we must continue finding its “Reduced Subtracted
Form(RSF)”
The resultant RSF (41) is two-digit number, so we have reached the “two-digit Reduced Subtracted
Form”.
If input1 = 5271
Expected output = 21
Explanation:
RSF of 356=(3-5)(5-6)=21
Note2:Note that while concatenating the differences, we are expected to use the absolute values(non-
negative)
Note3: The input values for all test cases in this program have been designed such that their two-digits
RSF will definitely result in a two-digit number
ANSWER:
while(input1>=10)
{
int x=input1,l=0;
while(input1>0)
{
input1=input1/10;
l++;
}
int a[]=new int[l];
int i=l-1;
while(x>0)
{
a[i]=x%10;
x=x/10;
i--;
}
for(int j=0;j<l-1;j++)
{
input1=input1*10+Math.abs(a[j]-a[j+1]);
}
}
return input1;
Find Password:
Detective Buckshee junior has been approached by the shantiniketan kids society for help in
finding the password to the games complex.After hearing the scenario,detective Buckshee
junior realises that he will need a programmer's support.He contacts you requests your help.
A numbers is stable if each of its digit occur the same number of times, i.e the frequency of each digit in
the number is the same.
Similarily,A number is unstable if the frequency of each digit in the number is NOT the same.For
eg:221,4314,101,233,58135,101 are examples of unstable numbers.
For example:
***********************************************************************
ANSWER:
import java.io.*;
import java.util.*;
class UserMainCode
{
public int findPassword(int input1,int input2,int input3,int input4,int input5){
int t1=input1,t2=input2,t3=input3,t4=input4,t5=input5;
int stable_sum=0,unstable_sum=0,i;
while(input1>0)
h1[input1%10]++;
input1/=10;
while(input2>0)
h2[input2%10]++;
input2/=10;
while(input3>0)
h3[input3%10]++;
input3/=10;
}
while(input4>0)
h4[input4%10]++;
input4/=10;
while(input5>0)
h5[input5%10]++;
input5/=10;
for(i=0;i<10;i++)
//System.out.print(" ");
int c=0;
for(i=0;i<10;i++)
if(h1[i]!=0)
c=h1[i];
break;
//System.out.print(c);
for(i=0;i<10;i++)
if(h1[i]!=0)
if(c!=h1[i])
unstable_sum+=1;
break;
if(i==10)
stable_sum+=1;
for(i=0;i<10;i++)
if(h2[i]!=0)
c=h2[i];
break;
for(i=0;i<10;i++)
if(h2[i]!=0)
{
if(c!=h2[i])
unstable_sum+=1;
break;
if(i==10)
stable_sum+=1;
for(i=0;i<10;i++)
if(h3[i]!=0)
c=h3[i];
break;
for(i=0;i<10;i++)
if(h3[i]!=0)
if(c!=h3[i])
unstable_sum+=1;
break;
}
if(i==10)
stable_sum+=1;
for(i=0;i<10;i++)
if(h4[i]!=0)
c=h4[i];
break;
for(i=0;i<10;i++)
if(h4[i]!=0)
if(c!=h4[i])
unstable_sum+=1;
break;
}
if(i==10)
stable_sum+=1;
for(i=0;i<10;i++)
if(h5[i]!=0)
c=h5[i];
break;
for(i=0;i<10;i++)
if(h5[i]!=0)
if(c!=h5[i])
unstable_sum+=1;
break;
if(i==10)
stable_sum+=1;
return unstable_sum*10+stable_sum;
}
}
Detective Buckshee junior has been approached by the shantiniketan kids society for help in
finding the password to the games complex.After hearing the scenario,detective Buckshee
junior realises that he will need a programmer's support.He contacts you requests your help.
A numbers is stable if each of its digit occur the same number of times, i.e the frequency of each digit in
the number is the same.
Similarily ,A number is unstable if the frequency of each digit in the number is NOT the same.For
eg:221,4314,101,233,58135,101 are examples of unstable numbers.
ANSWER:
import java.io.*;
import java.util.*;
class UserMainCode
int t1=input1,t2=input2,t3=input3,t4=input4,t5=input5;
int stable_sum=0,unstable_sum=0,i;
while(input1>0)
{
h1[input1%10]++;
input1/=10;
while(input2>0)
h2[input2%10]++;
input2/=10;
while(input3>0)
h3[input3%10]++;
input3/=10;
while(input4>0)
h4[input4%10]++;
input4/=10;
while(input5>0)
h5[input5%10]++;
input5/=10;
for(i=0;i<10;i++)
{
System.out.println(h1[i]+" "+h2[i]+" "+h3[i]+" "+h4[i]+" "+h5[i]);
//System.out.print(" ");
int c=0;
for(i=0;i<10;i++)
if(h1[i]!=0)
c=h1[i];
break;
//System.out.print(c);
for(i=0;i<10;i++)
if(h1[i]!=0)
if(c!=h1[i])
unstable_sum+=1;
break;
if(i==10)
stable_sum+=1;
for(i=0;i<10;i++)
if(h2[i]!=0)
c=h2[i];
break;
for(i=0;i<10;i++)
if(h2[i]!=0)
if(c!=h2[i])
unstable_sum+=1;
break;
if(i==10)
stable_sum+=1;
for(i=0;i<10;i++)
if(h3[i]!=0)
{
c=h3[i];
break;
for(i=0;i<10;i++)
if(h3[i]!=0)
if(c!=h3[i])
unstable_sum+=1;
break;
if(i==10)
stable_sum+=1;
for(i=0;i<10;i++)
if(h4[i]!=0)
c=h4[i];
break;
}
}
for(i=0;i<10;i++)
if(h4[i]!=0)
if(c!=h4[i])
unstable_sum+=1;
break;
if(i==10)
stable_sum+=1;
for(i=0;i<10;i++)
if(h5[i]!=0)
c=h5[i];
break;
for(i=0;i<10;i++)
if(h5[i]!=0)
{
if(c!=h5[i])
unstable_sum+=1;
break;
if(i==10)
stable_sum+=1;
return stable_sum*10+unstable_sum;
Detective Buckshee junior has been approached by the shantiniketan kids society for help in
finding the password to the games complex.After hearing the scenario,detective Buckshee
junior realises that he will need a programmer's support.He contacts you requests your help.
A numbers is stable if each of its digit occur the same number of times, i.e the frequency of each digit in
the number is the same.
Similarily ,A number is unstable if the frequency of each digit in the number is NOT the same.For
eg:221,4314,101,233,58135,101 are examples of unstable numbers.
For example:
ANSWER:
import java.util.*;
String s="";
int st=0,u=0;
int min=Integer.MAX_VALUE;
int max=Integer.MIN_VALUE;
for(int i=0;i<input.length;i++){
for(int j=0;j<10;j++)
h[j]=0;
s=String.valueOf(input[i]);
for(int j=0;j<s.length();j++){
h[Integer.parseInt(s.substring(j,j+1))]++;
int c=0,k=-1,flag=0;
for(int j=0;j<10;j++){
k=h[j];
c++;
flag=1;
break;
if(flag==1)
if(input[i]<min)
min=input[i];
}
else
if(input[i]>max)
max=input[i];
return max+min;
int n1=sc.nextInt();
int n2=sc.nextInt();
int n3=sc.nextInt();
int n4=sc.nextInt();
int n5=sc.nextInt();
System.out.println(MaxMinStableSum(n1,n2,n3,n4,n5));
finding the password to the games complex. After hearing the scenario, detective Buckshee
junior realizes that he will need a programmer's support. He contacts you requests your help.
A numbers is stable if each of its digit occur the same number of times, i.e the frequency of each digit in
the number is the same.
Similarly, A number is unstable if the frequency of each digit in the number is NOT the same. For
eg:221,4314,101,233,58135,101 are examples of unstable numbers.
Assuming that the five numbers are passed to a function as input1, input2, input3, input4, input5.
Complete the function to find and return the password.
For example:
So, the password should be=sum of all stable numbers – sum of all Unstable numbers=983
ANSWER:
import java.io.*;
import java.util.*;
// Read only region start
class UserMainCode
int t1=input1,t2=input2,t3=input3,t4=input4,t5=input5;
int stable_sum=0,unstable_sum=0,i;
while(input1>0)
h1[input1%10]++;
input1/=10;
while(input2>0)
h2[input2%10]++;
input2/=10;
}
while(input3>0)
h3[input3%10]++;
input3/=10;
while(input4>0)
h4[input4%10]++;
input4/=10;
while(input5>0)
h5[input5%10]++;
input5/=10;
for(i=0;i<10;i++)
//System.out.print(" ");
int c=0;
for(i=0;i<10;i++)
if(h1[i]!=0)
c=h1[i];
break;
//System.out.print(c);
for(i=0;i<10;i++)
if(h1[i]!=0)
if(c!=h1[i])
unstable_sum+=t1;
break;
//System.out.print(unstable_sum);
if(i==10)
stable_sum+=t1;
for(i=0;i<10;i++)
if(h2[i]!=0)
c=h2[i];
break;
}
}
for(i=0;i<10;i++)
if(h2[i]!=0)
if(c!=h2[i])
unstable_sum+=t2;
break;
if(i==10)
stable_sum+=t2;
for(i=0;i<10;i++)
if(h3[i]!=0)
c=h3[i];
break;
for(i=0;i<10;i++)
if(h3[i]!=0)
{
if(c!=h3[i])
unstable_sum+=t3;
break;
if(i==10)
stable_sum+=t3;
for(i=0;i<10;i++)
if(h4[i]!=0)
c=h4[i];
break;
for(i=0;i<10;i++)
if(h4[i]!=0)
if(c!=h4[i])
unstable_sum+=t4;
break;
if(i==10)
stable_sum+=t4;
for(i=0;i<10;i++)
if(h5[i]!=0)
c=h5[i];
break;
for(i=0;i<10;i++)
if(h5[i]!=0)
if(c!=h5[i])
unstable_sum+=t5;
break;
}
}
if(i==10)
stable_sum+=t5;
return stable_sum-unstable_sum;
Detective Buckshee junior has been approached by the shantiniketan kids society for help in
finding the password to the games complex. After hearing the scenario, detective Buckshee
junior realizes that he will need a programmer's support. He contacts you requests your help.
A numbers is stable if each of its digit occur the same number of times, i.e the frequency of each digit in
the number is the same.
Similarly, A number is unstable if the frequency of each digit in the number is NOT the same. For
eg:221,4314,101,233,58135,101 are examples of unstable numbers.
Assuming that the five numbers are passed to a function as input1, input2, input3, input4, input5.
Complete the function to find and return the password.
For example:
So, the Password should be=Maximum of all stable numbers - Minimum of all Unstable numbers=1313-
122=1191
ANSWER:
import java.util.*;
String s="";
int st=0,u=0;
int min=Integer.MAX_VALUE;
int max=Integer.MIN_VALUE;
for(int i=0;i<input.length;i++){
for(int j=0;j<10;j++)
h[j]=0;
s=String.valueOf(input[i]);
for(int j=0;j<s.length();j++){
h[Integer.parseInt(s.substring(j,j+1))]++;
int c=0,k=-1,flag=0;
for(int j=0;j<10;j++){
c++;
flag=1;
break;
if(flag==1)
if(input[i]<min)
min=input[i];
else
if(input[i]>max)
max=input[i];
return max-min;
int n1=sc.nextInt();
int n2=sc.nextInt();
int n3=sc.nextInt();
int n4=sc.nextInt();
int n5=sc.nextInt();
System.out.println(MaxMinStableSum(n1,n2,n3,n4,n5));
Detective Buckshee junior has been approached by the shantiniketan kids society for help in
finding the password to the games complex. After hearing the scenario, detective Buckshee
junior realizes that he will need a programmer's support. He contacts you requests your help.
A numbers is stable if each of its digit occur the same number of times, i.e the frequency of each digit in
the number is the same.
Similarly, A number is unstable if the frequency of each digit in the number is NOT the same. For
eg:221,4314,101,233,58135,101 are examples of unstable numbers.
For example:
So, the Password should be=Maximum of all Unstable numbers - Minimum of all Unstable
numbers=898-122=776
ANSWER:
import java.util.*;
String s="";
int l=0;
for(int i=0;i<input.length;i++){
for(int j=0;j<10;j++)
h[j]=0;
s=String.valueOf(input[i]);
for(int j=0;j<s.length();j++){
h[Integer.parseInt(s.substring(j,j+1))]++;
int c=0,k=-1,flag=0;
for(int j=0;j<10;j++){
k=h[j];
c++;
flag=1;
break;
if(flag==1)
res[l++]=input[i];
int min=Integer.MAX_VALUE,max=Integer.MIN_VALUE;
for(int i=0;i<l;i++)
if(res[i]<min)
min=res[i];
if(res[i]>max)
max=res[i];
return max-min;
int n2=sc.nextInt();
int n3=sc.nextInt();
int n4=sc.nextInt();
int n5=sc.nextInt();
System.out.println(MaxMinStableSum(n1,n2,n3,n4,n5));
Detective Buckshee junior has been approached by the shantiniketan kids society for help in
finding the password to the games complex. After hearing the scenario, detective Buckshee
junior realizes that he will need a programmer's support. He contacts you requests your help.
A numbers is stable if each of its digit occur the same number of times, i.e the frequency of each digit in
the number is the same.
Similarly, A number is unstable if the frequency of each digit in the number is NOT the same. For
eg:221,4314,101,233,58135,101 are examples of unstable numbers.
Assuming that the five numbers are passed to a function as input1, input2, input3, input4, input5.
Complete the function to find and return the password.
For example:
ANSWER:
import java.io.*;
import java.util.*;
class UserMainCode
int t1=input1,t2=input2,t3=input3,t4=input4,t5=input5;
int unstable_sum=0,i;
while(input1>0)
h1[input1%10]++;
input1/=10;
while(input2>0)
h2[input2%10]++;
input2/=10;
while(input3>0)
h3[input3%10]++;
input3/=10;
while(input4>0)
h4[input4%10]++;
input4/=10;
while(input5>0)
h5[input5%10]++;
input5/=10;
}
int c=0;
for(i=0;i<10;i++)
if(h1[i]!=0)
c=h1[i];
break;
for(i=0;i<10;i++)
if(h1[i]!=0)
if(c!=h1[i])
unstable_sum+=t1;
break;
for(i=0;i<10;i++)
if(h2[i]!=0)
{
c=h2[i];
break;
for(i=0;i<10;i++)
if(h2[i]!=0)
if(c!=h2[i])
unstable_sum+=t2;
break;
for(i=0;i<10;i++)
if(h3[i]!=0)
c=h3[i];
break;
for(i=0;i<10;i++)
{
if(h3[i]!=0)
if(c!=h3[i])
unstable_sum+=t3;
break;
for(i=0;i<10;i++)
if(h4[i]!=0)
c=h4[i];
break;
for(i=0;i<10;i++)
if(h4[i]!=0)
if(c!=h4[i])
unstable_sum+=t4;
break;
for(i=0;i<10;i++)
if(h5[i]!=0)
c=h5[i];
break;
for(i=0;i<10;i++)
if(h5[i]!=0)
if(c!=h5[i])
unstable_sum+=t5;
break;
return unstable_sum;
}
Detective Buckshee junior has been approached by the shantiniketan kids society for help in
finding the password to the games complex. After hearing the scenario, detective Buckshee
junior realizes that he will need a programmer's support. He contacts you requests your help.
A numbers is stable if each of its digit occur the same number of times, i.e the frequency of each digit in
the number is the same.
Similarly, A number is unstable if the frequency of each digit in the number is NOT the same. For
eg:221,4314,101,233,58135,101 are examples of unstable numbers.
Assuming that the five numbers are passed to a function as input1, input2, input3, input4, input5.
Complete the function to find and return the password.
For example:
So, the Password should be=Maximum of all stable numbers - Minimum of all stable numbers=1313-
12=1301
ANSWER:
import java.util.*;
String s="";
int l=0;
for(int i=0;i<input.length;i++){
for(int j=0;j<10;j++)
h[j]=0;
s=String.valueOf(input[i]);
for(int j=0;j<s.length();j++){
h[Integer.parseInt(s.substring(j,j+1))]++;
int c=0,k=-1,flag=0;
for(int j=0;j<10;j++){
k=h[j];
c++;
break;
if(flag==0)
res[l++]=input[i];
int min=Integer.MAX_VALUE,max=Integer.MIN_VALUE;
for(int i=0;i<l;i++)
if(res[i]<min)
min=res[i];
if(res[i]>max)
max=res[i];
return max-min;
int n1=sc.nextInt();
int n2=sc.nextInt();
int n3=sc.nextInt();
int n4=sc.nextInt();
int n5=sc.nextInt();
System.out.println(MaxMinStableSum(n1,n2,n3,n4,n5));
}
Detective Buckshee junior has been approached by the shantiniketan kids society for help in
finding the password to the games complex. After hearing the scenario, detective Buckshee
junior realizes that he will need a programmer's support. He contacts you requests your help.
A numbers is stable if each of its digit occur the same number of times, i.e the frequency of each digit in
the number is the same.
Similarly, A number is unstable if the frequency of each digit in the number is NOT the same. For
eg:221,4314,101,233,58135,101 are examples of unstable numbers.
Assuming that the five numbers are passed to a function as input1, input2, input3, input4, input5.
Complete the function to find and return the password.
For example:
If input1=12,input2=1313,input3=122,input4=678 and input5=898 , we see that there are THREE stable
numbers 12,1313 and 678 and
So, the Password should be=Maximum of all stable numbers + Minimum of all stable numbers=1313 +
12=1325
ANSWER:
import java.util.*;
String s="";
int l=0;
for(int i=0;i<input.length;i++){
for(int j=0;j<10;j++)
h[j]=0;
s=String.valueOf(input[i]);
for(int j=0;j<s.length();j++){
h[Integer.parseInt(s.substring(j,j+1))]++;
int c=0,k=-1,flag=0;
for(int j=0;j<10;j++){
c++;
flag=1;
break;
if(flag==0)
res[l++]=input[i];
int min=Integer.MAX_VALUE,max=Integer.MIN_VALUE;
for(int i=0;i<l;i++)
if(res[i]<min)
min=res[i];
if(res[i]>max)
max=res[i];
return max+min;
int n1=sc.nextInt();
int n2=sc.nextInt();
int n3=sc.nextInt();
int n4=sc.nextInt();
int n5=sc.nextInt();
System.out.println(MaxMinStableSum(n1,n2,n3,n4,n5));