Wipro Assessment Questions With Solutions Part-1

1. Question:

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 realizes that he will need a programmers support. He contacts you and 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 number 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 the each digit in the number is

NOT the same, For e.g 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.


For Example: if input1=12, input2=1313, input3=122, input4=676, and

input5=898,

stable numbers are 12, 1313 and 678

unstable numbers are 122 and 898

So, the password should be=sum of all unstable numbers=1020







import java.io.*;
import java.util.*;
class fiir
{
public static void main(String ar[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int sum=0;
int inp[]=new int[n];

for(int m=0;m<n;m++)
{
inp[m]=sc.nextInt();
}
int dig[]=new int[10];
int un=0,st=0;
//char c[];
String s=" ";
String sstr="";
String ustr="";
TreeSet<Integer> tr=new TreeSet<Integer>();
for(int i=0;i<inp.length;i++)
{
s=String.valueOf(inp[i]);
char c[]=s.toCharArray();


int narr[]=new int[c.length];
for(int j=0;j<c.length;j++)
{
narr[j]=Integer.parseInt(String.valueOf(c[j]));
}

for( int k=0;k<narr.length;k++)
{
dig[narr[k]]=(dig[narr[k]])+1;
}

for(int p=0;p<10;p++)
{
if(dig[p]!=0)
{
tr.add(dig[p]);
}
}

if(tr.size()>1)
{
un=un+1;
ustr+=s+" ";
}
else
{
st=st+1;
sstr+=s+" ";
}

for(int o=0;o<10;o++)
{
dig[o]=0;
}
tr.clear();
}

String uarray[]=ustr.split(" ");
int unum[]=new int[uarray.length];
for( int t=0;t<uarray.length;t++)
{
Integer.parseInt(String.valueOf(uarray[t]));
unum[t]=Integer.parseInt(String.valueOf(uarray[t]));

sum=sum+unum[t];
}
System.out.println(sum);

}
}


-----------------------------------------------------------------------


2. Question:

Detective buckshee junior has been approached by the shantinketan 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 and request 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 number 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 example 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 example 221,4314,101,233,58135,101 are example of unstable numbers



If input 1=12. Input2=1313, input3=122, input4=678, 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 =(Largest frequency of smallest of all stable numbers)*( second smallest digit of all unstable numbers)

THREE stable numbers i.e. 12, 1313 and 678 and

Freq of 1=3

Freq of 2=1

Freq of 3=2

Freq of 6=1

Freq of 7=1

Freq of 8=1

So the largest frequency among all the stable numbers is 3 i.e 1 occurs 3 times and it is the smallest

TWO Unstable numbers i.e. 122 and 898



Second smallest digit among all unstable numbers i.e. 122 and 898 is 2

So the password should be 3*2=6









import java.util.*;
class fgh
{
public static void main(String ar[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int inp[]=new int[n];
int i1,j1,count;
for(int m=0;m<n;m++)
{
inp[m]=sc.nextInt();
}
int dig[]=new int[10];
int un=0,st=0;
String s=" ";
String sstr="";
String ustr="";
String ustr1="";
int valuear[]=new int[10];
TreeSet<Integer> tr=new TreeSet<Integer>();
for(int i=0;i<inp.length;i++)
{
s=String.valueOf(inp[i]);
char c[]=s.toCharArray();
int narr[]=new int[c.length];
for(int j=0;j<c.length;j++)
{
narr[j]=Integer.parseInt(String.valueOf(c[j]));
}
for( int k=0;k<narr.length;k++)
{
dig[narr[k]]=(dig[narr[k]])+1;
}
for(int p=0;p<10;p++)
{
if(dig[p]!=0)
{
tr.add(dig[p]);
}
}
//System.out.println(tr.size());
if(tr.size()>1)
{
un=un+1;
ustr+=s+" ";
ustr1+=s;
}
else
{
st=st+1;
sstr+=s+" ";
}

for(int o=0;o<10;o++)
{
dig[o]=0;
}
tr.clear();
}
System.out.println(ustr1);
int sela[]=new int[ustr1.length()];
char c2[]=ustr1.toCharArray();
for(int i=0;i<c2.length;i++)
{
sela[i]=Integer.parseInt(String.valueOf(c2[i]));
System.out.println(sela[i]);
}
Arrays.sort(sela);
int moni=sela[1];
System.out.println("second :"+moni);
String sarray[]=sstr.split(" ");
int snum[]=new int[sarray.length];
for(int i=0;i<sarray.length;i++)
{
snum[i]=Integer.parseInt(String.valueOf(sarray[i]));
}
Arrays.sort(snum);
int a=snum[sarray.length-1];
System.out.println("biggest: "+a);
String uarray[]=ustr.split(" ");
int unum[]=new int[uarray.length];
for(int t=0;t<uarray.length;t++)
{
unum[t]=Integer.parseInt(String.valueOf(uarray[t]));
}
Arrays.sort(unum);
int b=unum[0];
System.out.println("smallest:"+b);
System.out.println("total:"+(a+b));
System.out.println("Un:"+un+"\n"+"st:"+st);
int pass=(un*10)+st;
System.out.println(pass);
String nand="";
for(int p=0;p<sarray.length;p++)
{
nand+=String.valueOf(snum[p]);
}
char carr1[]=nand.toCharArray();
int narr2[]=new int[carr1.length];
for( i1=0;i1<carr1.length;i1++)
narr2[i1]=Integer.parseInt(String.valueOf(carr1[i1]));
for(i1=0;i1<10;i1++)
{
count=0;
for(j1=0;j1<narr2.length;j1++)
{
if(narr2[j1]==i1)
{
count=count+1;
}
}
valuear[i1]=count;
}
String ans="";
for(i1=0;i1<valuear.length;i1++)
{
if(valuear[i1]!=0)
ans+=valuear[i1];
}
char ch[]=ans.toCharArray();
int narr1[]=new int[ch.length];
for(i1=0;i1<ch.length;i1++)
{
narr1[i1]=Integer.parseInt(String.valueOf(ch[i1]));
}
int min=narr1[0];
for(i1 = 1; i1 <narr1.length; i1++)
{
 if(min<narr1[i1])
{
min=narr1[i1];
}
}

for(i1=0;i1<valuear.length;i1++)
{
if(valuear[i1]==min)
{
System.out.println(i1);
break;
}
}
System.out.println("password:"+(min*moni));
}
}


-----------------------------------------------------------------------


3. Question:

Assume that the five numbers are passed to a function as input1, input2, input3, input4 and input5,

Complete the function to find and return the password.

4) If input 1=12. Input2=1313, input3=122, input4=678, 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 =( Lower frequency of smaller of all stable numbers)+( second largest digit of all unstable numbers)

THREE stable numbers i.e. 12, 1313 and 678 and

Freq of 1=3

Freq of 2=1

Freq of 3=2

Freq of 6=1

Freq of 7=1

Freq of 8=1

So the lower frequency among all the stable numbers is 1 i.e 2,6,7,8 occur 1 times and 2 is the smallest digit.

TWO Unstable numbers i.e. 122 and 898

Second largest digit among all unstable numbers i.e. 122 and 898 is 8

So the password should be 2+8=10




import java.util.*;
class fgh
{
public static void main(String ar[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int inp[]=new int[n];
int i1,j1,count;
for(int m=0;m<n;m++)
{
inp[m]=sc.nextInt();
}
int dig[]=new int[10];
int un=0,st=0;
String s=" ";
String sstr="";
String ustr="";
String ustr1="";
int valuear[]=new int[10];
TreeSet<Integer> tr=new TreeSet<Integer>();
for(int i=0;i<inp.length;i++)
{
s=String.valueOf(inp[i]);
char c[]=s.toCharArray();
int narr[]=new int[c.length];
for(int j=0;j<c.length;j++)
{
narr[j]=Integer.parseInt(String.valueOf(c[j]));
}
for( int k=0;k<narr.length;k++)
{
dig[narr[k]]=(dig[narr[k]])+1;
}
for(int p=0;p<10;p++)
{
if(dig[p]!=0)
{
tr.add(dig[p]);
}
}
//System.out.println(tr.size());
if(tr.size()>1)
{
un=un+1;
ustr+=s+" ";
ustr1+=s;
}
else
{
st=st+1;
sstr+=s+" ";
}

for(int o=0;o<10;o++)
{
dig[o]=0;
}
tr.clear();
}
System.out.println(ustr1);
int sela[]=new int[ustr1.length()];
char c2[]=ustr1.toCharArray();
for(int i=0;i<c2.length;i++)
{
sela[i]=Integer.parseInt(String.valueOf(c2[i]));
System.out.println(sela[i]);
}
Arrays.sort(sela);
int moni=sela[c2.length-2];
System.out.println("second :"+moni);
String sarray[]=sstr.split(" ");
int snum[]=new int[sarray.length];
for(int i=0;i<sarray.length;i++)
{
snum[i]=Integer.parseInt(String.valueOf(sarray[i]));
}
Arrays.sort(snum);
int a=snum[sarray.length-1];
System.out.println("biggest: "+a);
String uarray[]=ustr.split(" ");
int unum[]=new int[uarray.length];
for(int t=0;t<uarray.length;t++)
{
unum[t]=Integer.parseInt(String.valueOf(uarray[t]));
}
Arrays.sort(unum);
int b=unum[0];
System.out.println("smallest:"+b);
System.out.println("total:"+(a+b));
System.out.println("Un:"+un+"\n"+"st:"+st);
int pass=(un*10)+st;
System.out.println(pass);
String nand="";
for(int p=0;p<sarray.length;p++)
{
nand+=String.valueOf(snum[p]);
}
char carr1[]=nand.toCharArray();
int narr2[]=new int[carr1.length];
for( i1=0;i1<carr1.length;i1++)
narr2[i1]=Integer.parseInt(String.valueOf(carr1[i1]));
for(i1=0;i1<10;i1++)
{
count=0;
for(j1=0;j1<narr2.length;j1++)
{
if(narr2[j1]==i1)
{
count=count+1;
}
}
valuear[i1]=count;
}
String ans="";
for(i1=0;i1<valuear.length;i1++)
{
if(valuear[i1]!=0)
ans+=valuear[i1];
}
char ch[]=ans.toCharArray();
int narr1[]=new int[ch.length];
for(i1=0;i1<ch.length;i1++)
{
narr1[i1]=Integer.parseInt(String.valueOf(ch[i1]));
}
int min=narr1[0];
for(i1 = 1; i1 <narr1.length; i1++)
{
 if(min>narr1[i1])
{
min=narr1[i1];
}
}

for(i1=0;i1<valuear.length;i1++)
{
if(valuear[i1]==min)
{
System.out.println(i1);
break;
}
}
System.out.println("password:"+(i1+moni));
}
}



---------------------------------------------------------------------------


4. Question:

Assume that the five numbers are passed to a function as input1, input2, input3, input4 and input5,

Complete the function to find and return the password.

5) If input 1=12. Input2=1313, input3=122, input4=678, 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 = A four digit number

thousandth position = largest digit of all stable numbers

hundredth position = largest digit of all unstable numbers ,

tenth position = smallest digit of all unstable numbers

ones position is smallest digit of all stable numbers

THREE stable numbers i.e. 12, 1313 and 678 and

TWO Unstable numbers i.e. 122 and 898

Largest digit of all stable numbers is 8

Smallest digit of all stable numbers is 1

Largest digit of all unstable numbers is 9

Smallest digit of all unstable numbers is 1

password =8911

Assume that the five numbers are passed to a function as input1, input2, input3, input4 and input5,

Complete the function to find and return the password.





import java.util.*;
class stableM
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int a[]=new int[n];
int x=0,num=0,i=0,t=0;
ArrayList<Integer> al=new ArrayList<Integer>();
ArrayList<Integer> all=new ArrayList<Integer>();
String set="";
int st=0,uns=0,ans=0;
for( i=0;i<n;i++)
a[i]=s.nextInt();
for( i=0;i<n;i++)
{
int b[]=new int[10];
num=a[i];
while(num>0)
{
x=num%10;
num=num/10;
b[x]++;
}
TreeSet<Integer> ts=new TreeSet<Integer>();
for(x=0;x<10;x++)
{
if(b[x]!=0)
{
ts.add(b[x]);
}
}
if(ts.size()==1)
{
al.add(a[i]);
}
else
{
all.add(a[i]);
}
}
//System.out.println(all);
Integer li1[]=new Integer[al.size()];
Integer li2[]=new Integer[all.size()];
li1=al.toArray(li1);
li2=all.toArray(li2);
String q="";
String u="";
String strr="";
String sto="";
for(i=0;i<li1.length;i++)
{
strr=String.valueOf(li1[i]);
q+=strr;
}

for(i=0;i<li2.length;i++)
{
sto=String.valueOf(li2[i]);
u+=sto;
}
char ch[]=q.toCharArray();
char chh[]=u.toCharArray();
int f[]=new int[ch.length];
int w[]=new int[chh.length];
for(i=0;i<ch.length;i++)
{
f[i]=Integer.parseInt(String.valueOf(ch[i]));
}
for(i=0;i<chh.length;i++)
{
w[i]=Integer.parseInt(String.valueOf(chh[i]));
}
Arrays.sort(f);
Arrays.sort(w);
System.out.println(f[0]+" "+f[f.length-1]);
System.out.println(w[0]+" "+w[w.length-1]);
System.out.print("Password:");
System.out.print(f[f.length-1]);
System.out.print(w[w.length-1]);
System.out.print(f[0]);
System.out.println(w[0]);
}
}

----------------------------------------------------------------------



Assume that the five numbers are passed to a function as input1, input2, input3, input4 and input5,

Complete the function to find and return the password.

3) If input 1=12. Input2=1313, input3=122, input4=678, 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



Eg. THREE stable numbers i.e. 12, 1313 and 678 and

Freq of 1=3

Freq of 2=1

Freq of 3=2

Freq of 6=1

Freq of 7=1

Freq of 8=1

a. Largest frequency is 3 i.e 1 occurs 3 times and 1 is the smallest digit.

b. Smallest frequency is 1 i.e 2,6,7,8 occur 1 time & 8 is the largest digit.

TWO Unstable numbers i.e. 122 and 898

Freq of 1=1

Freq of 2=2

Freq of 8=2

Freq of 9=1

c. Largest frequency is 2 i.e 2& 8 occur 2 times & 2 is the smallest digit.

d. Smallest frequency is 1 i.e 1& 9 occur 1 time & 9 is the largest digit.

So, the password =a+b+c+d=1+8+2+9=20







import java.util.*;
class fgh5
{
public static void main(String ar[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int i1,j1,count,count1;
int inp[]=new int[n];
int a1=0,b1=0,c1=0,d1=0;
for(int m=0;m<n;m++)
{
inp[m]=sc.nextInt();
}
int dig[]=new int[10];
int un=0,st=0;
//char c[];
String s=" ";
String sstr="";
String ustr="";
int valuear[]=new int[10];
int valuear1[]=new int[10];
TreeSet<Integer> tr=new TreeSet<Integer>();
for(int i=0;i<inp.length;i++)
{
s=String.valueOf(inp[i]);
char c[]=s.toCharArray();

//System.out.println(c.length);
int narr[]=new int[c.length];
for(int j=0;j<c.length;j++)
{
narr[j]=Integer.parseInt(String.valueOf(c[j]));
}
for(int j=0;j<c.length;j++)
{
System.out.println("carr"+narr[j]);
}

for( int k=0;k<narr.length;k++)
{
dig[narr[k]]=(dig[narr[k]])+1;
}
for( int k=0;k<10;k++)
{
System.out.println("index:"+k+" "+dig[k]);
}
for(int p=0;p<10;p++)
{
if(dig[p]!=0)
{
tr.add(dig[p]);
}
}
System.out.println(tr.size());
if(tr.size()>1)
{
un=un+1;
ustr+=s+" ";
}
else
{
st=st+1;
sstr+=s+" ";
}

for(int o=0;o<10;o++)
{
dig[o]=0;
}
tr.clear();
}
System.out.println(sstr);
String sarray[]=sstr.split(" ");
int snum[]=new int[sarray.length];
for(int i=0;i<sarray.length;i++)
{
snum[i]=Integer.parseInt(String.valueOf(sarray[i]));
System.out.println(snum[i]);
}
int a=snum[sarray.length-1];
System.out.println(ustr);
String uarray[]=ustr.split(" ");
int unum[]=new int[uarray.length];
for(int t=0;t<uarray.length;t++)
{
unum[t]=Integer.parseInt(String.valueOf(uarray[t]));
System.out.println(unum[t]);
}
String nand="";
for(int p=0;p<sarray.length;p++)
{
nand+=String.valueOf(snum[p]);
}
char carr1[]=nand.toCharArray();
int narr2[]=new int[carr1.length];
for( i1=0;i1<carr1.length;i1++)
narr2[i1]=Integer.parseInt(String.valueOf(carr1[i1]));
for(i1=0;i1<10;i1++)
{
count=0;
for(j1=0;j1<narr2.length;j1++)
{
if(narr2[j1]==i1)
{
count=count+1;
}
}
valuear[i1]=count;
}
String ans="";
for(i1=0;i1<valuear.length;i1++)
{
if(valuear[i1]!=0)
ans+=valuear[i1];
}
char ch[]=ans.toCharArray();
int narr1[]=new int[ch.length];
for(i1=0;i1<ch.length;i1++)
{
narr1[i1]=Integer.parseInt(String.valueOf(ch[i1]));
}
int min1=narr1[0];
for(i1 = 1; i1 <narr1.length; i1++)
{
 if(min1>narr1[i1])
{
min1=narr1[i1];
}
}
int min=narr1[0];
for(i1 = 1; i1 <narr1.length; i1++)
{
 if(min<narr1[i1])
{
min=narr1[i1];
}
}
for(i1=0;i1<valuear.length;i1++)
{
if(valuear[i1]==min)
{
a1=i1;
break;
}
}
for(i1=valuear.length-1;i1>=0;i1--)
{
if(valuear[i1]==min1)
{
b1=i1;
break;
}
}
System.out.println(a1);
System.out.println(b1);
System.out.println("***************");
String nand1="";
for(int p=0;p<uarray.length;p++)
{
nand1+=String.valueOf(unum[p]);
}
char carr2[]=nand1.toCharArray();
int narr3[]=new int[carr2.length];
for( i1=0;i1<carr2.length;i1++)
{
narr3[i1]=Integer.parseInt(String.valueOf(carr2[i1]));
}
for(i1=0;i1<10;i1++)
{
count1=0;
for(j1=0;j1<narr3.length;j1++)
{
if(narr3[j1]==i1)
{
count1=count1+1;
}
}
valuear1[i1]=count1;
}
String ans1="";
for(i1=0;i1<valuear1.length;i1++)
{
if(valuear1[i1]!=0)
ans1+=valuear1[i1];
}
char ch1[]=ans1.toCharArray();
int narr4[]=new int[ch1.length];
for(i1=0;i1<ch1.length;i1++)
{
narr4[i1]=Integer.parseInt(String.valueOf(ch1[i1]));
}
int min2=narr4[0];
for(i1 = 1; i1 <narr4.length; i1++)
{
 if(min2>narr4[i1])
{
min2=narr4[i1];
}
}
for(i1=valuear1.length-1;i1>=0;i1--)
{
if(valuear1[i1]==min2)
{
d1=i1;
break;
}
}
int min3=narr4[0];
for(i1 = 1; i1 <narr4.length; i1++)
{
if(min3<narr4[i1])
{
min3=narr4[i1];
}
}
for(i1=0;i1<valuear1.length;i1++)
{
if(valuear1[i1]==min3)
{
c1=i1;
break;
}
}
System.out.println(c1);
System.out.println(d1);
System.out.println("password:"+(a1+b1+c1+d1));
}
}

Comments

Post a Comment

Popular Posts