100% found this document useful (2 votes)
18K views52 pages

Milestone 1

The document describes a method to find a password based on analyzing whether numbers are stable or unstable. Numbers are stable if the frequency of each digit is the same, unstable otherwise. The password is calculated as the number of unstable numbers multiplied by 10, plus the number of stable numbers. An example is provided where the numbers 12, 1313, 122, 678, 898 yield a password of 23, as there are 2 unstable (122, 898) and 3 stable (12, 1313, 678) numbers. A Java function is provided that takes the 5 numbers as input, analyzes the digit frequencies of each to determine stable/unstable, counts stable and unstable, and returns the password.

Uploaded by

Venkatesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
18K views52 pages

Milestone 1

The document describes a method to find a password based on analyzing whether numbers are stable or unstable. Numbers are stable if the frequency of each digit is the same, unstable otherwise. The password is calculated as the number of unstable numbers multiplied by 10, plus the number of stable numbers. An example is provided where the numbers 12, 1313, 122, 678, 898 yield a password of 23, as there are 2 unstable (122, 898) and 3 stable (12, 1313, 678) numbers. A Java function is provided that takes the 5 numbers as input, analyzes the digit frequencies of each to determine stable/unstable, counts stable and unstable, and returns the password.

Uploaded by

Venkatesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

1.

Find Key:

You are provided with 3 numbers : input1, input2 and input3.

Each of these are 4 digits numbers within >=1000 and <=9999

i.e.,

1000<=input1<=9999

1000<=input2<=9999

1000<=input3<=9999

You are expected to find the key using below formula:

Key = Sum of Largest digits of each number + Sum of Second Largest digits of each
number

For Example, input1=3521, input2=2452 input3=1352

Key = (5+5+5) + (3+4+3) = 25

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;

2. FIND KEY(DIFFERENT TESTCASE WITH DIFFERENT MODEL-2)

Find Key:

You are provided with 3 numbers input1,input2,input3.

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]

for e.g if input1=3521,input2=2452,input3=1352,then Key=[1][5][2][2]=1522

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)

You are provided with 3 numbers input1,input2,input3.

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]

for e.g if input1=3521,input2=2452,input3=1352,then Key=[3][3][5][1]=3351

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 –

Difference between 6 and 9 is 3

Difference between 9 and 2 is 7

Difference between 2 and 8 is 6

So, the “Reduced Subtracted Form(RSF)” of 6928 = 376

The resultant RSF (376) is not a two-digit number, so we must continue finding its “Reduced Subtracted
Form(RSF)”

Difference between 3 and 7 is 4

Difference between 7 and 6 is 1

So, the “Reduced Subtracted Form(RSF)” of 376 = 41

The resultant RSF (41) is two-digit number, so we have reached the “two-digit Reduced Subtracted
Form”.

Therefore, the two-digit RSF of 6928 = 41

Let’s see another example

If input1 = 5271

Expected output = 21

Explanation:

RSF of 5271 = (5-2)(2-7)(7-1)=356

RSF of 356=(3-5)(5-6)=21

Note1: input1 will be always be >=100

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:

Two digit reduced subtracted form

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.

Please help the detective by writing a function to generate the password.

The scenario is as below-

Five numbers are available with the kids.


These numbers are either stable or unstable

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.

For e.g:2277,4004,11,23,583835,1010 are examples of stable numbers.

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.

The password can be found as below-

i.e password=(Number of unstable numbers*10)+Number of stable 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 i.e 12,1313 and 678 and

TWO unstable numbers i.e 122 and 898

so,the password should be=(Number of Unstable numbers*10)+Number of stable


numbers=(2*10)+3=23

***********************************************************************

ANSWER:

import java.io.*;

import java.util.*;

// Read only region start

class UserMainCode

{
public int findPassword(int input1,int input2,int input3,int input4,int input5){

// Read only region end

// Write code here...

int[] h1=new int[10];

int[] h2=new int[10];

int[] h3=new int[10];

int[] h4=new int[10];

int[] h5=new int[10];

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 unstable_sum*10+stable_sum;

}
}

19) 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.

Please help the detective by writing a function to generate the password.

The scenario is as below-

Five numbers are available with the kids.

These numbers are either stable or unstable

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.

For e.g:2277,4004,11,23,583835,1010 are examples of stable numbers.

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.

The password can be found as below-

i.e password=(Number of stable numbers*10)+Number 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 i.e 12,1313 and 678 and

TWO unstable numbers i.e 122 and 898

so,the password should be=(Number of stable numbers*10)+Number of Unstable


numbers=(3*10)+1=32

ANSWER:

import java.io.*;

import java.util.*;

// Read only region start

class UserMainCode

public int findPassword(int input1,int input2,int input3,int input4,int input5){

// Read only region end

// Write code here...

int[] h1=new int[10];

int[] h2=new int[10];

int[] h3=new int[10];

int[] h4=new int[10];

int[] h5=new int[10];

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;

20) 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.

Please help the detective by writing a function to generate the password.

The scenario is as below-

Five numbers are available with the kids.


These numbers are either stable or unstable

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.

For e.g:2277,4004,11,23,583835,1010 are examples of stable numbers.

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.

The password can be found as below-

i.e Password=Maximum of all stable numbers+Minimum of all 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 i.e 12,1313 and 678 and

TWO unstable numbers i.e 122 and 898

so,the password should be=Maximum of all stable numbers+Minimum of all Unstable


numbers=1313+122=1435

ANSWER:

import java.util.*;

public class MyClass {

public static int MaxMinStableSum(int input1,int input2,int input3,int input4,int input5){

int input[]=new int[]{input1,input2,input3,input4,input5};

int h[]=new int[10];

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++){

if(h[j]!=0 && c==0){

k=h[j];

c++;

if(h[j]!=0 && h[j]!=k){

flag=1;

break;

if(flag==1)

if(input[i]<min)

min=input[i];
}

else

if(input[i]>max)

max=input[i];

return max+min;

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);

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));

21) FIND PASSWORD(DIFFERENT TESTCASE WITH MODEL-4)


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.

Please help the detective by writing a function to generate the password.

The scenario is as below-

Five numbers are available with the kids.

These numbers are either stable or unstable

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.

For e.g:2277,4004,11,23,583835,1010 are examples of stable numbers.

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.

The password can be found as below-

i.e Password=sum of all stable numbers - sum of all 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

TWO unstable numbers 122 and 898

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

public int findPassword(int input1,int input2,int input3,int input4,int input5){

// Read only region end

// Write code here...

int[] h1=new int[10];

int[] h2=new int[10];

int[] h3=new int[10];

int[] h4=new int[10];

int[] h5=new int[10];

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+=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;

22) FIND PASSWORD (DIFFERENT TESTCASE WITH MODEL – 5)

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.

Please help the detective by writing a function to generate the password.

The scenario is as below-

Five numbers are available with the kids.

These numbers are either stable or unstable

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.

For e.g:2277,4004,11,23,583835,1010 are examples of stable numbers.

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.

The password can be found as below-

i.e Password=Maximum of all stable numbers - Minimum of all 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

TWO unstable numbers 122 and 898

So, the Password should be=Maximum of all stable numbers - Minimum of all Unstable numbers=1313-
122=1191

ANSWER:

import java.util.*;

public class MyClass {

public static int MaxMinStableSum(int input1,int input2,int input3,int input4,int input5){

int input[]=new int[]{input1,input2,input3,input4,input5};

int h[]=new int[10];

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++){

if(h[j]!=0 && c==0){


k=h[j];

c++;

if(h[j]!=0 && h[j]!=k){

flag=1;

break;

if(flag==1)

if(input[i]<min)

min=input[i];

else

if(input[i]>max)

max=input[i];

return max-min;

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);

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));

23)FIND PASSWORD(DIFFERENT TESTCASE WITH MODEL-6)

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.

Please help the detective by writing a function to generate the password.

The scenario is as below-

Five numbers are available with the kids.

These numbers are either stable or unstable

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.

For e.g:2277,4004,11,23,583835,1010 are examples of stable numbers.

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.

The password can be found as below-

i.e Password=Maximum of all Unstable numbers - Minimum of all 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

TWO unstable numbers 122 and 898

So, the Password should be=Maximum of all Unstable numbers - Minimum of all Unstable
numbers=898-122=776

ANSWER:

import java.util.*;

public class MyClass {

public static int MaxMinStableSum(int input1,int input2,int input3,int input4,int input5){

int input[]=new int[]{input1,input2,input3,input4,input5};

int h[]=new int[10];

String s="";

int l=0;

int res[]=new int[input.length];

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++){

if(h[j]!=0 && c==0){

k=h[j];

c++;

if(h[j]!=0 && h[j]!=k){

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;

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);


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));

24) FIND PASSWORD(DIFFERENT TESTCASE WITH MODEL-7)

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.

Please help the detective by writing a function to generate the password.

The scenario is as below-

Five numbers are available with the kids.

These numbers are either stable or unstable

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.

For e.g:2277,4004,11,23,583835,1010 are examples of stable numbers.

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.

The password can be found as below-


i.e Password=sum of all 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

TWO unstable numbers 122 and 898

So, the Password should be=sum of all Unstable numbers=898-122=1020

ANSWER:

import java.io.*;

import java.util.*;

// Read only region start

class UserMainCode

public int findPassword(int input1,int input2,int input3,int input4,int input5){

// Read only region end

// Write code here...

int[] h1=new int[10];

int[] h2=new int[10];

int[] h3=new int[10];

int[] h4=new int[10];

int[] h5=new int[10];

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;
}

25)FIND PASSWORD(DIFFERENT TESTCASE WITH MODEL-8)

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.

Please help the detective by writing a function to generate the password.

The scenario is as below-

Five numbers are available with the kids.

These numbers are either stable or unstable

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.

For e.g:2277,4004,11,23,583835,1010 are examples of stable numbers.

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.

The password can be found as below-

i.e Password=Maximum of all stable numbers - Minimum of all stable 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
TWO unstable numbers 122 and 898

So, the Password should be=Maximum of all stable numbers - Minimum of all stable numbers=1313-
12=1301

ANSWER:

import java.util.*;

public class MyClass {

public static int MaxMinStableSum(int input1,int input2,int input3,int input4,int input5){

int input[]=new int[]{input1,input2,input3,input4,input5};

int h[]=new int[10];

String s="";

int l=0;

int res[]=new int[input.length];

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++){

if(h[j]!=0 && c==0){

k=h[j];

c++;

if(h[j]!=0 && h[j]!=k){


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;

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);

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));
}

26) FIND PASSWORD(DIFFERENT TESTCASE WITH MODEL-9)

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.

Please help the detective by writing a function to generate the password.

The scenario is as below-

Five numbers are available with the kids.

These numbers are either stable or unstable

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.

For e.g:2277,4004,11,23,583835,1010 are examples of stable numbers.

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.

The password can be found as below-

i.e Password=Maximum of all stable numbers + Minimum of all stable 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

TWO unstable numbers 122 and 898

So, the Password should be=Maximum of all stable numbers + Minimum of all stable numbers=1313 +
12=1325

ANSWER:

import java.util.*;

public class MyClass {

public static int MaxMinStableSum(int input1,int input2,int input3,int input4,int input5){

int input[]=new int[]{input1,input2,input3,input4,input5};

int h[]=new int[10];

String s="";

int l=0;

int res[]=new int[input.length];

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++){

if(h[j]!=0 && c==0){


k=h[j];

c++;

if(h[j]!=0 && h[j]!=k){

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;

public static void main(String args[]) {

Scanner sc=new Scanner(System.in);

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));

You might also like