Pascal’s Triangle is a problem that asks us to generate the first n rows of Pascal’s Triangle. Pascal’s Triangle is a triangular array of integers that is formed by starting with a row of 1 and then adding the two numbers above it to get the next row.
Inside the for loop, we can initialize a new row called “currentRow” and set it equal to an array of 1s with the same length as the current loop iteration + 1. Then, we can use another loop to iterate through the elements of the current row, starting at index 1 and ending at the second to last element. Inside this inner loop, we can set the value of the current element equal to the sum of the previous element in the current row and the element in the previous row at the same index.
Finally, we can push the current row into the triangle array and return the triangle array once the outer loop has been completed.
This solution has a time complexity of O(n^2), as we have a nested loop that both have a time complexity of O(n).