ThoughtWorks Interview Question
Software Engineer / Developersseries is
2 2 4 11
difference series is
0 2 7
Again take difference series
2 5
Again
3
so we have 3 now.
add 3 to its above series => 2 5 8
now add this 8 to last term of its above series => 0 2 7 15
Now add this 15 to last term of its above series =>2 2 4 11 26
This is what I mean :)
I think since the series given was short, the purpose of the question was to rather see how many solutions a candidate can come up with, than getting the exact solution they were looking for. It might be a trick question -- just saying.
However, here's how I would do it:
2,2,4,11 -- the difference between consecutive terms is: 0,2,7... which can be looked at as:
2^0 -1 = 0
2^1 -0 = 2
2^3 -1 = 7
so the next difference would be:
2^4 -0 = 16
which gives the next term as 11+16 = 27.
I've never played around with the base x fibonacci, neither heard of it before... but whoever thought about it... RESPECT! ;)
2,2,4,11 the diff bt conseccutive terms is 0,2,7
0^1+1=2
2^2+3=7
7^3+5=348
therfore the next number in the series is 359
2,2,4,7,11,359
pehle toh yeh batao..jayda dimag aa gaya hai kya
kuh bhi bana rahe hooo aur hum man le..
Numbers : 2,2,4,11
Difference : 0,2,7
sequence :
0 = 0^0
2 = 1^1 + 1^0
7 = 2^2 + 2^1 + 2^0
Next number in sequence of differences : 3^3 + 3^2 + 3^1 + 3^0 = 40
Next Number in the original Sequence = 51 (40 + 11)
if we take 7 as a base then solution will be
a1=2;
a2=2;
a3=a1+a2;//a3=2+2=4
a4=a1+a2+a3;//a4=2+2+4=8(in decimal)
/*
8=11(in base 7)
*/
a5=a1+a2+a3+a4//a5=2+2+4+11=19(in decimal)
/*
19=25(in base 7)
*/
hence ans may be 25
2, 2, 4, 11
First set of Differences = 0,2,7
Second set of Differences (of the first difference set) = 2,4,.... ie 2*1 = 2, 2*2 = 4, or 2^1 = 2, 2^2 = 4
so assuming the next difference is either of the following -
2*3 = 6, OR 2^3=8
The next number in the Second set of differences would either be 6 or 8
ie 2,4,6 or 2,4,8
Then the next number in the First set of differences would either be -
7+6= 13 OR 7+8 = 15
Last number of original series could either be -
11+13 = 24, or 11+15=26
And finally the series itself might be -
2,2,4,11,24
OR
2,2,4,11,26
g(n) = 2 for n=0;
g(n) = g(n-1) + f(n-1) for n>0
f(n) = n * n + (Sum of i where i runs from 0 to n)
g(0)=2
g(1) = g(1-1) + f(1-1)
= g(0) + f(0)
= 2 + ((0*0)+(0))
= 2
g(2) = g(2-1) + f(2-1)
= g(1) + f(1)
= 2 + ((1*1)+(1+0))
= 2 + (1 + 1)
= 4
g(3) = g(3-1) + f(3-1)
= g(2) + f(2)
= 4 + ((2*2)+(2+1+0))
= 4 + (4 + 3)
= 11
g(4) = g(4-1) + f(4-1)
= g(3) + f(3)
= 11 + ((3*3)+(3+2+1+0))
= 11 + (9 + 6)
= 26
1. Sort the given numbers in ascending order (Say as 2 , 4 ,6 7)
2. Represent them in binary (0010,0100,0110,0111)
3. Represent all the once in the set as set of number (say 2,3,{2,3},{1,2,3})
4. Take the once from the first set and remove them from all sets and make a new set
a. Take out 2 so new set is {3,{3},{1,3}}
b. Now Take out 3 so new set is {1}
c. Now take out 1 and it is done
So the answer is {0010,0100,0001} i.e 2,4,1
public class TestSeries {
public static void main(String[] args) {
seriesTest1();
}
public static void seriesTest1(){
int arr[]={2,2,4,11,26};
for(int i=0; i<arr.length; i++) {
int j = i * i + getFact(i);
System.out.println(arr[i]+j+"->"+i+"->"+j);
}
}
public static int getFact(int factInput) {
int response = 0;
for(int i=factInput;i>=1; i--) {
response += i;
}
return response;
}
}
There is another way to do it. Answer is 61,
Explanation :
Given number series, 2,2,4,11
Using factorial, leave the first number from the series. and add other numbers in the series with the previous given number.
Example, factorial of 2 is 1,2
Now Leave the the 1st number and add with the previous number. Previous number empty. So,
(1) 2 + 0 (previous number) = 2
(1) 2 + 2 (previous number) = 4
(1) 2 + 3 + 4 + 2 (previous number) = 11
(1) 2 + 3 +... +11 + 4 (previous number) = 61
take 5 ary system it consists digits 0,1,2,3,4
(for example binary system contains 0,1 and decimal system contains 0 to 9)
lets take fibonacci series with a1=2 and a2=2
then a3= 2+2=4
a4= 2+4= which is six but 5 ary system doesn't contain six as a digit
how can six can be represented using 5 ary system??
11 = 5*1 + 1*1
2,2,4,11....
- Abhay July 22, 2011difference between the n and n-1...follows the sequence 0,2,7...
now 0 can be made as 0*0=0,similar 2 can be made as 1*1+1=2 and 7 can be made as 2*2+2+1=7,following the sequence we get the next difference as 15(3*3+3+2+1)..therefore the next number is 26 in the series.