Skip to content
← Back to the archive

3 September 2026 · Advanced track

Shortest Balanced Stretch

Advanced Lists Numbers

Find the shortest run of sensor readings that adds up exactly to a target value.

A conveyor belt sensor logs a small integer adjustment value every second. The value can be positive, negative, or zero. Find the length of the shortest contiguous stretch of readings that adds up to exactly a target amount. Return that length as an integer. If no stretch of readings adds up to the target, return -1.

Constraints

  • readings is a list of integers and can include negative numbers, positive numbers, or zero
  • readings can be empty
  • target is an integer
  • If readings is empty, or no contiguous stretch sums to target, return -1

Function signature

def shortest_balanced_stretch(readings, target):

Sign in to solve this bracket

Reading the problem is free for everyone. Opening the editor and solving it requires an account with Open Bracket+.