Oracle Interview Question
Software Engineer / DevelopersThe question says that,
Each alphabet represents a digit. It is a 10 digit number.
ABCDEFGHIJ
First digit(A) represents the number of 0's in the number. Second digit(B) represents the number of 1's in the number and so on.
Question is: Find the 10 digit number satisfying the above condition.
"
" can you tell me how did you proceed in finding the solution of this question, are there any more number which are following this pattern "
"
There is only one solution, take any 10 digit number and keep fixing it for number of digits present, you will end up with number chungwei gave.
the sum of those digits in the number has to be 10
A+B+...+K=10
since they are the number of respective (based on pocession) digits in that number .
Take any 10 digit number and start moving.
eg.-
lets take -
0123400000 // sum of digits is 10
4123410000 ->
4213410000 ->
5210401000 ->
6210001000
Number is : 6210001000
public class puzzle
{
static int a[]=new int[10];
static int getNumberCount(int searchnumber)
{
int count=0;
for(int i=0;i<10;i++)
{
if(a[i]==searchnumber)
count++;
}
return count;
}
public static void main(String args[])
{
for(a[0]=1;a[0]<=9;a[0]++)
for(a[1]=0;a[1]<=9;a[1]++)
for(a[2]=0;a[2]<=9;a[2]++)
for(a[3]=0;a[3]<=9;a[3]++)
for(a[4]=0;a[4]<=9;a[4]++)
for(a[5]=0;a[5]<=9;a[5]++)
for(a[6]=0;a[6]<=9;a[6]++)
for(a[7]=0;a[7]<=9;a[7]++)
for(a[8]=0;a[8]<=9;a[8]++)
for(a[9]=0;a[9]<=9;a[9]++)
{
if(a[0]==getNumberCount(0) && a[1]==getNumberCount(1) &&a[2]==getNumberCount(2) &&a[3]==getNumberCount(3) &&a[4]==getNumberCount(4) &&a[5]==getNumberCount(5)&&a[6]==getNumberCount(6)&&a[7]==getNumberCount(7)&&a[8]==getNumberCount(8)&&a[9]==getNumberCount(9))
System.out.println("Number : "+a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]);
}
}
}
Number is : 6210001000
public class puzzle
{
static int a[]=new int[10];
static int getNumberCount(int searchnumber)
{
int count=0;
for(int i=0;i<10;i++)
{
if(a[i]==searchnumber)
count++;
}
return count;
}
public static void main(String args[])
{
for(a[0]=1;a[0]<=9;a[0]++)
for(a[1]=0;a[1]<=9;a[1]++)
for(a[2]=0;a[2]<=9;a[2]++)
for(a[3]=0;a[3]<=9;a[3]++)
for(a[4]=0;a[4]<=9;a[4]++)
for(a[5]=0;a[5]<=9;a[5]++)
for(a[6]=0;a[6]<=9;a[6]++)
for(a[7]=0;a[7]<=9;a[7]++)
for(a[8]=0;a[8]<=9;a[8]++)
for(a[9]=0;a[9]<=9;a[9]++)
{
if(a[0]==getNumberCount(0) && a[1]==getNumberCount(1) &&a[2]==getNumberCount(2) &&a[3]==getNumberCount(3) &&a[4]==getNumberCount(4) &&a[5]==getNumberCount(5)&&a[6]==getNumberCount(6)&&a[7]==getNumberCount(7)&&a[8]==getNumberCount(8)&&a[9]==getNumberCount(9))
System.out.println("Number : "+a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]);
}
}
}
It's harder to understand the question than to actually find the solution.
- Anonymous June 05, 2010