Programowanie konkurencyjneCiężko

Maksymalny prostokąt sumy

Szczegółowy przewodnik i implementacja Python dla problemu „Prostokąt sumy maksymalnej”.

Oświadczenie o problemie

Ciężko

Napisz funkcję max_sum_rectangle(matrix), która znajduje i zwraca maksymalną sumę podmacierzy w dwuwymiarowej macierzy liczb całkowitych.

Ograniczenia
  • 1 <= len(matrix), len(matrix[0]) <= 100
  • -1000 <= matrix[i][j] <= 1000

Przykłady

Example 1
Input
max_sum_rectangle([[1, 2, -1, -4, -20], [-8, -3, 4, 2, 1], [3, 8, 10, 1, 3], [-4, -1, 1, 7, -6]])
Output
29
Explanation

The sub-matrix from row 1, column 1 to row 3, column 3 has the maximum sum of 29.

Example 2
Input
max_sum_rectangle([[-1, -2], [-3, -4]])
Output
-1
Explanation

The maximum sum is -1, which is the cell at (0, 0).

Need a Hint?
Rozważ użycie struktur danych specyficznych dla programowania dynamicznego, takich jak zestawy lub sterty.
Edge Cases to Watch
  • Puste struktury wejściowe
  • Wejścia jednoelementowe
  • Duże granice liczbowe

Gotowy do rozwiązania?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Otwórz w Edytorze
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Polecane zasoby Pythona

Poszerzaj swoją wiedzę dzięki powiązanym interaktywnym samouczkom, ściągawkom i porównaniom kodów.