BackmediumUncategorized uncategorized medium

Balanced Subsequence Sums Solution

Problem Statement

You are given an array of integers `sequence` of length `n`, find all subsequences of length `9` where the sum of the first `7` elements equals the sum of the last `7` elements, and the middle element is the maximum of the subsequence.

Example 1
Input
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Output
[[1, 2, 3, 4, 5, 6, 7, 8, 9]]

Explanation: The sum of the first 7 elements (1+2+3+4+5+6+7) equals the sum of the last 7 elements (3+4+5+6+7+8+9) and the middle element 5 is the maximum of the subsequence.

Constraints

  • 1 <= n <= 1000
  • 1 <= sequence[i] <= 1000
  • The subsequence must have exactly 9 elements
  • The middle element must be the maximum of the subsequence
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free