Have you heard of the sliding window algorithm?
3-Second Blueprint (English)
- To find the highest-sum contiguous group of size K, avoid recounting all K items from scratch at every starting position.
- Compute the initial sum of the first K items once, then advance the window forward one item at a time.
- Update the running total in constant work per step by subtracting the outgoing left item and adding the incoming right item.
Sliding WindowRunning SumContiguous Subarray
3-Sekunden-Fazit (Deutsch)
- Um die Teilgruppe der Länge K mit der größten Summe zu finden, vermeidet man das komplette Neuzählen an jeder Startposition.
- Man berechnet einmalig die Summe der ersten K Elemente und verschiebt das Fenster danach jeweils um eine Position weiter.
- Die laufende Summe wird pro Schritt aktualisiert, indem man das herausfallende Element abzieht und das hinzukommende addiert.
Sliding WindowLaufende SummeZusammenhängendes Subarray
Note / Hinweis: Blueprints are AI-generated educational summaries (0% Politics · 0% Religion · 0% Brainrot) and do not constitute medical, legal, or financial advice. / KI-generierte Zusammenfassung zu Bildungszwecken – ersetzt keine medizinische, rechtliche oder finanzielle Fachberatung.