Day 7: Buying 2 Chocolate Boxes
mediumsliding windowtwo pointersPrefix Sum
You are given a sequence of chocolate boxes, where the -th box contains chocolates.
You want to buy two disjoint sets of contiguous chocolate boxes such that each set contains exactly chocolates in total. Your goal is to minimize the total number of boxes you purchase.
Return the minimum total number of boxes needed to buy the two disjoint sets of chocolate boxes, or return if it is impossible to select two such disjoint segments.
Input Format:
The input consists of two lines:
- The first line contains two integers ( ), followed by ( )
- The second line contains integers ()
Output Format:
A single integer -- the minimum total number of boxes, or if it is impossible to select two disjoint segments each summing to .
Examples: