Dsa
Two Pointers
Easy
Max Edges Between Siblings
In a family tree represented as an array, siblings share the same parent. Given an array where each element represents the number of edges to their parent, you need to determine the maximum number of edges that may be passed between siblings within a given range of indices. Write a function that returns this maximum edge count.
Input Format:
- The first line contains two integers n (1 ≤ n ≤ 10^5) — the number of children, and k (1 ≤ k ≤ n) — the number of edges to consider.
- The second line contains n integers a_i (1 ≤ a_i ≤ 1000) — the edge counts for each child.
Output Format:
- Print the maximum sum of edges for any subarray of size k.
Example:
Input:
6 3
5 1 3 2 6 4
Output:
11
Key concepts
two_pointersarraymax_subarray
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now