@rheaxu, what is the time and space complexity of the above solution? I think it should be O(n^2) because we iterate n times in the worst case for each value of n. Space complexity, I think, should again be O(n^2) because we create a matrix and store values in it.

Pascal's Triangle