Maximizing Row Sums in Nested Lists: A Python Guide
School
McMaster University**We aren't endorsed by this school
Course
COMPSCI 1MD3
Subject
Computer Science
Date
Dec 10, 2024
Pages
2
Uploaded by MateElementWildcat24
from typing import List L = [[1,2,3],[4,5,6],[7,8,9]]L1 = [[1,2],[4],[7,8,9,10,11]]def f(L):for sub_list in L:print("Beginning of outter loop.")for num in sub_list:print("Beginning of inner loop.")print(num)def g(L):for i in range(len(L)):for j in range(len(L[i])):print("i, j = " + str(i) + ", " + str(j))print(L[i][j])def h1(n):for i in range(n):for j in range(n):print("i, j = " + str(i) + ", " + str(j))def h2(n):for i in range(n):for j in range(i):print("i, j = " + str(i) + ", " + str(j))def f2(L):for i in range(len(L)):L[i] = 0return 99def max_row_sum(m: List[List[int]]) -> int:"""Checks the sum of all the rows in m, and returns the max value.Assume all non-empty rows sum to something greater than 0>>> max_row_sum([[4, -1, 7], [5, 10, -2], [0, 5, 6]])13[[4, -1, 7],[5, 10, -2],[0, 5, 6]]>>> max_row_sum([])0>>> max_row_sum([[-5, 7, 1], []])3"""cur_max = 0for i in m:b = 0for j in i:if cur_max <= b: cur_max = b