noOfWays [ i ] will store count for value i . 3 extra values are to take care of cornser case n = 0
int noOfWays [ ] = new int [ n + 3 ] ; noOfWays [ 0 ] = 1 ; noOfWays [ 1 ] = 1 ; noOfWays [ 2 ] = 1 + 1 ;