The TransCompilator

Solved LeetCode program · 795 of 1,000

#1031 · Maximum Sum of Two Non-Overlapping Subarrays

Medium Array chunk-16.md

Original English source

The numbers is a list of 0, 6, 5, 2, 2, 5, 1, 9, and 4. The size is 9. The firstlen is 1, while the secondlen is 2. The prefix is a list of 10 zeros.
For every spot from 0 to 8.
Set item (spot plus 1) of prefix to item spot of prefix plus item spot of numbers.

The best is 0.
For every first from 0 to size minus firstlen.
For every second from 0 to size minus secondlen.
The firstsum is item (first plus firstlen) of prefix minus item first of prefix. The secondsum is item (second plus secondlen) of prefix minus item second of prefix. The apart is 0. If first plus firstlen is at most second, set apart to 1. If second plus secondlen is at most first, set apart to 1. If apart is 1 and firstsum plus secondsum is more than best, set best to firstsum plus secondsum.

Show best.

Open in Playground Browse all 1,000 problems

Expected stdout

20