0

Why is my code to find the 33th rowIndex of a Pascal Triangle giving me negative values?

class Solution {
    public List<Integer> getRow(int rowIndex) {
        
        List<Integer> result = new ArrayList<Integer>();
        for(int k=0; k<=rowIndex; k++){
            int mCk = 1;
            for(int i=0; i<k; i++){
                mCk *= (rowIndex-i);
                mCk /= (i+1);
            }
            result.add(mCk);
        }
        return result;
    }
}

Your input 33

Output

[1,33,528,5456,40920,237336,1107568,4272048,13884156,38567100,
 92561040,193536720,-3096621,-5002233,-7146047,-9051659,-10183116,
 -10183116,-9051658,-7146045,-5002231,-3096619,-1689064,-807813,
 -336588,-121171,-37283,-9665,-2071,-357,-47,-4,0,0]

Expected

[1,33,528,5456,40920,237336,1107568,4272048,13884156,38567100,
 92561040,193536720,354817320,573166440,818809200,1037158320,
 1166803110,1166803110,1037158320,818809200,573166440,354817320,
 193536720,92561040,38567100,13884156,4272048,1107568,237336,40920,
 5456,528,33,1]
Popovkov57
  • 179
  • 16
SilverCyber
  • 101
  • 9

0 Answers0