>>> triangle = [[1], [1, 1]] >>> current_row = [1, -1, 1] >>> calculate_current_element(triangle, current_row, 2, 1) >>> current_row [1, 2, 1]
(
triangle: list[list[int]],
current_row: list[int],
current_row_idx: int,
current_col_idx: int,
)
| 91 | |
| 92 | |
| 93 | def calculate_current_element( |
| 94 | triangle: list[list[int]], |
| 95 | current_row: list[int], |
| 96 | current_row_idx: int, |
| 97 | current_col_idx: int, |
| 98 | ) -> None: |
| 99 | """ |
| 100 | >>> triangle = [[1], [1, 1]] |
| 101 | >>> current_row = [1, -1, 1] |
| 102 | >>> calculate_current_element(triangle, current_row, 2, 1) |
| 103 | >>> current_row |
| 104 | [1, 2, 1] |
| 105 | """ |
| 106 | above_to_left_elt = triangle[current_row_idx - 1][current_col_idx - 1] |
| 107 | above_to_right_elt = triangle[current_row_idx - 1][current_col_idx] |
| 108 | current_row[current_col_idx] = above_to_left_elt + above_to_right_elt |
| 109 | |
| 110 | |
| 111 | def generate_pascal_triangle_optimized(num_rows: int) -> list[list[int]]: |
no outgoing calls
no test coverage detected