code: public static long binomialCoefficient(int n, int k)
      {
              if(n - k == 1 || k == 1)
                  return n;
  
              long [][] b = new long[n+1][n-k+1];
              b[0][0] = 1;
              for(int i = 1; i < b.length; i++)
              {
                  for(int j = 0; j < b[i].length; j++)
                  {
                      if(i == j || j == 0)    
                          b[i][j] = 1;
                      else if(j == 1 || i - j == 1)
                          b[i][j] = i;
                      else
                          b[i][j] = b[i-1][j-1] + b[i-1][j];
                  }
              }
              return b[n][n-k];
      }
docs: N choose K