from typing import List def longest_chain(submatrix: List[int]) -> int: \"\"\" Given a list of integers, return the length...

50.1K

Verified Solution

Question

Programming

from typing import List


def longest_chain(submatrix: List[int]) -> int:
\"\"\"
Given a list of integers, return the length of the longest chain of1's
that start from the beginning.

You MUST use a while loop for this! We will check.

>>> longest_chain([1, 1, 0])
2
>>> longest_chain([0, 1, 1])
0
>>> longest_chain([1, 0, 1])
1
\"\"\"
i = 0
a = []
while i < len(submatrix) and submatrix[i] != 0:
a.append(submatrix[i])
i += 1
return sum(a)


def largest_rectangle_at_position(matrix: List[List[int]], x: int,y: int
) -> int:
\"\"\"
Returns the area of the largest rectangle whose top left corner isat
position , in .

You MUST make use of here as you loop through each row
of the matrix. Do not modify the input matrix.

>>> case1 = [[1, 0, 1, 0, 0],
... [1, 0, 1, 1, 1],
... [1, 1, 1, 1, 1],
... [1, 0, 0, 1, 0]]
>>> largest_rectangle_at_position(case1, 0, 0)
4
>>> largest_rectangle_at_position(case1, 2, 0)
5
>>> largest_rectangle_at_position(case1, 1, 2)
6
\"\"\"

pass

replace the word pass with a function body byimplementing the 1st function. make sure nested loops can be a maxof 3. try to keep it as short as possible and fulfill the docstringrequirements

Answer & Explanation Solved by verified expert
3.5 Ratings (413 Votes)
from typing import Listdef longestchainsubmatrix Listint int i 0 a while i lensubmatrix and submatrixi 0    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students