@@ -0,0 +1,1405 @@
+package com.interview.dynamic;%0A%0A/**%0A * Date 03/28/2015%0A * @author tusroy%0A * %0A * Fibonacci series%0A * Given a number find the fibonacci series value for that number%0A * e.g n = 3 -%3E 3%0A *     n = 4 -%3E 5%0A *     n = 5 -%3E 8%0A *  %0A * Solution%0A * Recursively it can calculated very easily by f(n) = f(n-1) + f(n-2)%0A * For Dp version we do not recalculate f(n-1) and f(n-2) but keep it in a and b%0A * %0A * Test cases%0A * 1) Negative number%0A * 2) 0 %0A * 3) 1%0A * 4) Very high number%0A * %0A */%0Apublic class FibonacciSeries %7B%0A%0A    /**%0A     * Recursive and slow version. Recalculates same value over and over again.%0A     * Chokes for n greater than 60%0A     */%0A    public int fibonacciSeries(int n)%7B%0A        int a = 1;%0A        int b = 1;%0A        int c = 1; %0A        for(int i=2; i %3C= n; i++)%7B%0A            c = a + b;%0A            a = b;%0A            b = c;%0A        %7D%0A        return c;%0A    %7D%0A    %0A    /**%0A     * DP version where we do not recalculate values but just keep last 2%0A     * calculate values%0A     */%0A    public int fibonacciSeriesRecursive(int n)%7B%0A        if(n == 1 %7C%7C n == 0)%7B%0A            return 1;%0A        %7D%0A        return fibonacciSeriesRecursive(n-1) + fibonacciSeriesRecursive(n-2);%0A    %7D%0A    %0A    public static void main(String args%5B%5D)%7B%0A        FibonacciSeries fs = new FibonacciSeries();%0A        System.out.println(fs.fibonacciSeries(15));%0A        System.out.println(fs.fibonacciSeriesRecursive(15));%0A    %7D%0A    %0A%7D%0A

Fibonacci series question